Latest questions in Python

0 votes
1 answer

Python set Union and set Intersection operate differently?

When you do set() you are creating an empty ...READ MORE

May 24, 2018 in Python by charlie_brown
• 7,720 points
829 views
0 votes
1 answer

Traverse a list in reverse

for item in my_list[::-1]: ...READ MORE

May 23, 2018 in Python by Nietzsche's daemon
• 4,260 points
441 views
0 votes
1 answer

Inverting a python dictionary

inv_dict = {value: key for key, value ...READ MORE

May 23, 2018 in Python by Nietzsche's daemon
• 4,260 points
346 views
0 votes
1 answer

How to sort Counter by value using python?

Use the Counter.most_common() method, it'll sort the items for you: >>> ...READ MORE

May 23, 2018 in Python by charlie_brown
• 7,720 points
10,074 views
0 votes
1 answer

What does ' -> ' mean in Python function definitions?

It's a function annotation. In more detail, Python 2.x ...READ MORE

May 23, 2018 in Python by charlie_brown
• 7,720 points
665 views
0 votes
1 answer

Looping over two lists at once

You have to use the zip() function: for ...READ MORE

May 15, 2018 in Python by Nietzsche's daemon
• 4,260 points
1,560 views
0 votes
1 answer

Reading Unix Timestamp in Python

import datetime print(datetime.datetime.fromtimestamp(int("1284101485")).strftime('%Y-%m-%d %H:%M:%S')) That is the cleanest way ...READ MORE

May 15, 2018 in Python by Nietzsche's daemon
• 4,260 points
796 views
0 votes
1 answer

Can someone explain the behaviour of increment and decrement operators in python

down voteaccepted ++ is not an operator. It is ...READ MORE

May 15, 2018 in Python by aryya
• 7,450 points
1,530 views
0 votes
1 answer

Python join: why is it string.join(list) instead of list.join(string)?

950down voteaccepted It's because any iterable can be ...READ MORE

May 15, 2018 in Python by aryya
• 7,450 points
714 views
0 votes
1 answer

Python Setup file

 setup.py tells you that the module or the ...READ MORE

May 14, 2018 in Python by Nietzsche's daemon
• 4,260 points
303 views
0 votes
1 answer

Difference between '==' and 'is'

'==' checks for the equality of the ...READ MORE

May 14, 2018 in Python by Nietzsche's daemon
• 4,260 points
580 views
0 votes
2 answers

Do-while loop in Python

A more pythonic way would be this: ``` while ...READ MORE

Jul 6, 2020 in Python by Composer3
1,164 views
0 votes
1 answer

Increment operators in Python

Python has no unary operators. So use ...READ MORE

May 12, 2018 in Python by Hamartia's Mask
• 1,580 points
822 views
0 votes
1 answer

Remove duplicate elements in a list

Here is the code for this - list(set((list_of_numbers) For ...READ MORE

May 12, 2018 in Python by Hamartia's Mask
• 1,580 points
625 views
0 votes
1 answer

Deleting a list element by value

Use the remove() function: >>> p = [1, ...READ MORE

May 12, 2018 in Python by Hamartia's Mask
• 1,580 points
443 views
0 votes
1 answer

How to exit from Python without traceback?

shutil has many methods you can use. One ...READ MORE

May 11, 2018 in Python by charlie_brown
• 7,720 points
647 views
0 votes
2 answers

Manually raising (throwing) an exception in Python

Exception handling issues in python can easily ...READ MORE

Jan 18, 2019 in Python by nick
• 140 points
17,155 views
0 votes
2 answers

How do I copy a file in python?

copy a file in python  from shutil ...READ MORE

Mar 27, 2019 in Python by rajesh
• 1,270 points
986 views
+1 vote
1 answer

How to replace id with attribute corresponding to id of another table?

Use the following query statement and let ...READ MORE

Aug 8, 2018 in Python by Priyaj
• 58,090 points
2,097 views
+1 vote
1 answer

How can I map input to output without using dynamic()

Here am talking about my example you ...READ MORE

Aug 8, 2018 in Python by Priyaj
• 58,090 points
794 views
+1 vote
1 answer

Why is openpyxl is required for loading excel format files?

Well, it sounds like openpyxl is not ...READ MORE

Aug 8, 2018 in Python by Priyaj
• 58,090 points
811 views
0 votes
1 answer

Using quotes in python

Both the conventions for enclosing strings are ...READ MORE

May 9, 2018 in Python by Nietzsche's daemon
• 4,260 points
398 views
0 votes
1 answer

Uninstalling python packages

It is best to install pip in ...READ MORE

May 9, 2018 in Python by Nietzsche's daemon
• 4,260 points
325 views
0 votes
1 answer

Numpy: Multiplying large arrays with dtype=int8 is SLOW

Unfortunately, the "engine" behind the scenes is BLAS, ...READ MORE

May 9, 2018 in Python by charlie_brown
• 7,720 points
1,061 views
0 votes
1 answer

OSX 10.11 with py2app?

I'm not sure if this is your ...READ MORE

May 9, 2018 in Python by charlie_brown
• 7,720 points
1,078 views
0 votes
1 answer

SKLearn NMF Vs Custom NMF

The choice of the optimizer has a ...READ MORE

May 9, 2018 in Python by charlie_brown
• 7,720 points
1,448 views
+1 vote
2 answers

Measuring the distance between pixels on OpenCv with Python

You can try this: Mat pts1(nPts, 1, CV_8UC2), ...READ MORE

Aug 24, 2018 in Python by Omkar
• 69,230 points
10,199 views
0 votes
1 answer

Exiting a python program

Use the quit() function. This function can ...READ MORE

May 8, 2018 in Python by Nietzsche's daemon
• 4,260 points
310 views
0 votes
1 answer

Type checking in Python

Use the type() function with the variable ...READ MORE

May 8, 2018 in Python by Nietzsche's daemon
• 4,260 points
324 views
0 votes
1 answer

Reversing strings in Python

The fastest way to reverse string is ...READ MORE

May 7, 2018 in Python by Nietzsche's daemon
• 4,260 points
403 views
0 votes
1 answer

Python comments

Use docstrings for multi-line commenting -  """ Line 1 Line ...READ MORE

May 7, 2018 in Python by Nietzsche's daemon
• 4,260 points
517 views
0 votes
1 answer

What is the difference between list and tuple?

Lists are mutable(values can be changed) whereas ...READ MORE

May 5, 2018 in Python by aayushi
• 750 points
6,573 views
0 votes
1 answer

Raw_input method is not working in python3. How to use it?

raw_input is not supported anymore in python3. ...READ MORE

May 5, 2018 in Python by aayushi
• 750 points
3,117 views
0 votes
1 answer

Padding a string

>>> s = '1123' >>> print s.zfill(8) #desired ...READ MORE

May 4, 2018 in Python by Nietzsche's daemon
• 4,260 points
447 views
0 votes
1 answer

Removing surrounding whitespace

Try the strip() function:  s = s.strip() If you ...READ MORE

May 4, 2018 in Python by Nietzsche's daemon
• 4,260 points
594 views
0 votes
2 answers

How to calculate square root of a number in python?

calculate square root in python >>> import math ...READ MORE

Apr 2, 2019 in Python by anonymous
5,412 views
0 votes
1 answer

how to find factorial of a number?

You can find factorial by many ways. ...READ MORE

May 4, 2018 in Python by aayushi
• 750 points
1,474 views
0 votes
1 answer

Count the frequency of all list items

You can do this using a dictionary: dict((i, ...READ MORE

May 3, 2018 in Python by Nietzsche's daemon
• 4,260 points
567 views
0 votes
1 answer

Renaming columns of dataframes

Assign the new names to the column ...READ MORE

May 3, 2018 in Python by Nietzsche's daemon
• 4,260 points
383 views
0 votes
1 answer

What is the use of raw_input function in Python?

raw_input fuction is no longer available in ...READ MORE

May 2, 2018 in Python by aayushi
• 750 points
961 views
0 votes
1 answer

How to add a new line in Python?

You can use '\n' for a next ...READ MORE

May 2, 2018 in Python by aayushi
• 750 points
1,033 views
0 votes
1 answer

Create time lag in Python

import time time.sleep(10) READ MORE

May 2, 2018 in Python by Nietzsche's daemon
• 4,260 points
1,587 views
0 votes
1 answer

Deleting a dictionary entry in Python

Use pop(): mapping.pop("key_x") #key_x is a key entry Note ...READ MORE

May 2, 2018 in Python by Nietzsche's daemon
• 4,260 points
557 views
0 votes
1 answer

Unable to take input from user in Python

num = input("enter number") print(num) READ MORE

May 1, 2018 in Python by aayushi
• 750 points
611 views
0 votes
1 answer

Install pip in Python 3.4

Don't worry! Python already comes in default ...READ MORE

May 1, 2018 in Python by aayushi
• 750 points
3,038 views
0 votes
1 answer

Copying lists in python

Assigning one list to another one simply ...READ MORE

Apr 30, 2018 in Python by Nietzsche's daemon
• 4,260 points
459 views
0 votes
1 answer

List of lines from a file

with open(fname) as f: ...READ MORE

Apr 30, 2018 in Python by Nietzsche's daemon
• 4,260 points
366 views
0 votes
1 answer

Run Unix command within Python

From the python docs, use the subprocess ...READ MORE

Apr 27, 2018 in Python by Nietzsche's daemon
• 4,260 points
498 views
0 votes
1 answer

Merge two dicts

dict3 = dict1.copy() # merges ...READ MORE

Apr 27, 2018 in Python by Nietzsche's daemon
• 4,260 points
607 views
0 votes
2 answers

What is the use of Python language?

python is general purpose programming language.it very ...READ MORE

Mar 15, 2019 in Python by rajesh kumar
757 views