Trending questions in Python

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,724 views
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
804 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
869 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,655 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
1,018 views
0 votes
2 answers

multi line comment

‘’’ This is the way to Enter multi ...READ MORE

Jul 16, 2018 in Python by Priyaj
• 58,020 points
587 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,460 points
728 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
587 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
882 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
652 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
689 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
574 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,707 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
909 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
578 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
557 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,765 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,430 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,338 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
1,074 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,969 views
0 votes
1 answer

Numpy: Multiplying large arrays with dtype=int8 is SLOW

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

May 9, 2018 in Python by charlie_brown
• 7,720 points
1,275 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
615 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,460 points
913 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
545 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
979 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
788 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,795 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
879 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,265 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
1,257 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,880 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
832 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,459 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
607 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,246 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
429 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
665 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
1,220 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
777 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
647 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
547 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
566 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
768 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,425 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
773 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
499 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
441 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
662 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
781 views