Trending questions in Python

0 votes
1 answer

Join all strings in a list of strings

s = " ".join(myList) #here " " ...READ MORE

May 30, 2018 in Python by Nietzsche's daemon
• 4,260 points
521 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,426 views
0 votes
1 answer

Comparing strings in Python

Convert both the strings to either uppercase ...READ MORE

May 28, 2018 in Python by Nietzsche's daemon
• 4,260 points
603 views
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
798 views
0 votes
1 answer

Replacements for switch statement in Python?

You could use a dictionary: def f(x): ...READ MORE

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

How can I compare the content of two files in Python?

Assuming that your file unique.txt just contains ...READ MORE

Apr 16, 2018 in Python by charlie_brown
• 7,720 points
2,365 views
0 votes
1 answer

Enlarging a list using functions using append() and extend()

Let me illustrate this with an example ...READ MORE

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

Create and open a file in Python

file = open('text.txt', 'w+) READ MORE

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

What exactly does the .join() method do?

Look carefully at your output: 5wlfgALGbXOahekxSs9wlfgALGbXOahekxSs5 ^ ...READ MORE

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

Number of days between dates in Python

You can use the date module to ...READ MORE

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

Sorting a list of strings in Python

Use the sort function mylist.sort() READ MORE

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

Multiple line comment in Python

Try this ''' This is a multiline comment. I can ...READ MORE

May 31, 2018 in Python by charlie_brown
• 7,720 points
376 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,574 views
0 votes
1 answer

Looping over a string in python

for c in "string": ...READ MORE

May 28, 2018 in Python by Nietzsche's daemon
• 4,260 points
451 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,457 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
647 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,058 views
0 votes
1 answer

How can I find out the index of an element from row and column in Python?

You probably want to use np.ravel_multi_index: [code] import numpy ...READ MORE

Apr 16, 2018 in Python by charlie_brown
• 7,720 points
2,034 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
785 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,036 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
429 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
700 views
0 votes
1 answer

how to download and install Django rest framework?

To install Django, you can simply open ...READ MORE

Apr 24, 2018 in Python by Christine
• 15,790 points
1,598 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
334 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
806 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
570 views
0 votes
1 answer

How to perform web scraping with python?

Hey, there are various libraries used in ...READ MORE

Apr 20, 2018 in Python by aayushi
• 750 points
1,577 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,014 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
604 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
631 views
0 votes
1 answer

Python class inherits an object

Python 3.x: class MyClass(object): = new-style class class MyClass: ...READ MORE

Apr 17, 2018 in Python by anonymous
1,603 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
920 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
433 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
297 views
0 votes
1 answer

Iterating over multiple lists

import itertools for item in itertools.chain(listone, listtwo): #li ...READ MORE

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

Parse JSON in Python

import json data=json.loads(employee_data) print(data) READ MORE

Apr 26, 2018 in Python by aayushi
• 750 points
1,012 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
504 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
378 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
576 views
0 votes
1 answer

How to slice an array using python numpy? Is there any numpy tutorial which has covered all its operations?

Slicing is basically extracting particular set of ...READ MORE

Apr 24, 2018 in Python by Christine
• 15,790 points
989 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
316 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
393 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
546 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
314 views
0 votes
1 answer

How can I iterate through two lists in Parallel

You have to use the zip function ...READ MORE

Apr 17, 2018 in Python by anonymous
1,209 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
302 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
594 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
529 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
430 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
378 views