Trending questions in Python

+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,020 points
1,053 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,421 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,020 points
1,010 views
0 votes
0 answers

Cannot make connection to .accdb file using python

I am writing a script that needs ...READ MORE

Jun 7, 2018 in Python by aryya
• 7,460 points
1,818 views
0 votes
1 answer

.pyc files in python

.pyc files contain the bytecode which are ...READ MORE

Jun 22, 2018 in Python by Hamartia's Mask
• 1,580 points
914 views
0 votes
1 answer

Representing infinity

import math infinity = math.inf Now you can use ...READ MORE

Jun 27, 2018 in Python by Hamartia's Mask
• 1,580 points
700 views
0 votes
1 answer

dunder main in python

It is a check to see if ...READ MORE

Jun 21, 2018 in Python by Hamartia's Mask
• 1,580 points
914 views
0 votes
1 answer

Modules and Packages

A module is a single file imported ...READ MORE

Jun 27, 2018 in Python by Hamartia's Mask
• 1,580 points
630 views
0 votes
1 answer

Convert dictionary keys to a list

list.(dictionary.keys()) READ MORE

Jun 28, 2018 in Python by Hamartia's Mask
• 1,580 points
561 views
0 votes
1 answer

Multiple line comment in python

No, you can simply use triple codes ...READ MORE

Jun 28, 2018 in Python by v.liyyah
• 1,300 points
570 views
0 votes
1 answer

Chaining comparision

I assume you are talking about this ...READ MORE

Jun 26, 2018 in Python by Hamartia's Mask
• 1,580 points
600 views
0 votes
1 answer

Copying dictionaries

Deep copy -  dict2 = dict(dict1) Shallow copy - dict2 ...READ MORE

Jun 25, 2018 in Python by Hamartia's Mask
• 1,580 points
613 views
0 votes
1 answer

Searching for substrings

Use the in operator to do this. If ...READ MORE

Jun 28, 2018 in Python by Hamartia's Mask
• 1,580 points
484 views
0 votes
1 answer

How to sort a list of strings?

Basic answer: mylist = ["b", "C", "A"] mylist.sort() This modifies ...READ MORE

Jun 4, 2018 in Python by aryya
• 7,460 points
1,497 views
0 votes
1 answer

Creating a matrix in Python

You can create arrays of any number ...READ MORE

Jun 19, 2018 in Python by Hamartia's Mask
• 1,580 points
862 views
0 votes
1 answer

Call a shell command in Python?

Try this - os.system("commands and arguments") READ MORE

Jun 21, 2018 in Python by Hamartia's Mask
• 1,580 points
762 views
0 votes
1 answer

convert integer to strings

Yes, you can str() function. For example: a=10 str(a) output-' ...READ MORE

Jun 26, 2018 in Python by code.reaper12
• 3,500 points
553 views
0 votes
2 answers

Finding the index of a character in python string

You can use word.find('o') as well to ...READ MORE

Jun 1, 2018 in Python by george
• 200 points
1,558 views
0 votes
1 answer

List all contents of a folder

Use listfor() from the os library READ MORE

Jun 22, 2018 in Python by Hamartia's Mask
• 1,580 points
656 views
0 votes
1 answer

How can I convert a list of dictionaries from a CSV into a JSON object in Python?

You could try using the AST module. ...READ MORE

Apr 17, 2018 in Python by anonymous
3,458 views
0 votes
1 answer

How to get the size of a string in Python?

If you are talking about the length ...READ MORE

Jun 4, 2018 in Python by aryya
• 7,460 points
1,373 views
0 votes
1 answer

Extract element from a set without removing it

Use iter(): element = next(iter(set_1)) READ MORE

Jun 7, 2018 in Python by Hamartia's Mask
• 1,580 points
1,239 views
0 votes
1 answer

Split a string into a list of characters

This is easy. Just use the list() ...READ MORE

Jun 19, 2018 in Python by Hamartia's Mask
• 1,580 points
690 views
0 votes
1 answer

Need help writing a dataframe into a csv with the help of a loop

Using the following logic you can arrive ...READ MORE

Apr 17, 2018 in Python by anonymous
3,379 views
0 votes
1 answer

Copying files

copyfile(src, dst) This is from the shutil library https://d ...READ MORE

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

Pythonic Switch statement

You can implement it using dictionaries  def numbers_to_strings(argument): ...READ MORE

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

Using sequences

Lists are like arrays, except that their ...READ MORE

Jun 14, 2018 in Python by Hamartia's Mask
• 1,580 points
751 views
0 votes
1 answer

Deleting files

Use the rmtree() method from shutil library. ...READ MORE

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

Sorting a dictionary

It is not possible to sort to ...READ MORE

Jun 18, 2018 in Python by Hamartia's Mask
• 1,580 points
534 views
0 votes
1 answer

Remove a string suffix

You can remove the substring using slicing. ...READ MORE

Jun 7, 2018 in Python by Hamartia's Mask
• 1,580 points
977 views
0 votes
1 answer

Print contents of a folder

There is a function provided in python ...READ MORE

Jun 18, 2018 in Python by Hamartia's Mask
• 1,580 points
495 views
0 votes
1 answer

Using exceptions in Python

They are used for control flow. Check ...READ MORE

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

Compare dates

>>> from datetime import datetime >>> past = ...READ MORE

Jun 14, 2018 in Python by Hamartia's Mask
• 1,580 points
645 views
0 votes
1 answer

reversing a list

Use the reverse function!  list_1.reverse() READ MORE

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

Python Whitespace for indenting

PEP-8 recommends creating indents by tapping the ...READ MORE

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

Install mysqldb module

pip install mysqlclient READ MORE

Jun 12, 2018 in Python by Hamartia's Mask
• 1,580 points
616 views
0 votes
2 answers

Delete a character from pythons string

If you want to remove the 'J' ...READ MORE

Jun 12, 2018 in Python by anonymous
699 views
0 votes
1 answer

Normal Python code equivalent to given list comprehension

You can try this code list1=[] for i in ...READ MORE

Jun 8, 2018 in Python by jain12
• 170 points
777 views
0 votes
1 answer

Binary numbers in python

>>> 0b1011 11 READ MORE

Jun 6, 2018 in Python by Hamartia's Mask
• 1,580 points
828 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,460 points
1,743 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,709 views
0 votes
1 answer

How to read/process command line arguments?

The canonical solution in the standard library ...READ MORE

Jun 4, 2018 in Python by aryya
• 7,460 points
813 views
0 votes
1 answer

How can I get a list of locally installed Python modules?

Solution My 50 cents for getting a pip freeze-like ...READ MORE

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

Combine list items to a string

>>> stmt = ['this','is','a','statement'] >>> ' '.join(sentence) 'this is ...READ MORE

Jun 7, 2018 in Python by Hamartia's Mask
• 1,580 points
641 views
0 votes
1 answer

Using Lists and Tuples in Python

if you are familiar with C programming, ...READ MORE

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

Size of an object in Python

Use sys.getsizeof() function: >>> import sys >>> s = ...READ MORE

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

Swapping values

a,b = b,a Here, python interprets the comma ...READ MORE

Jun 8, 2018 in Python by Hamartia's Mask
• 1,580 points
553 views
0 votes
1 answer

Extract all characters of a string

Convert it to a list -  s = ...READ MORE

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

What are the differences between type() and isinstance()?

To summarize the contents of other (already ...READ MORE

Jun 4, 2018 in Python by aryya
• 7,460 points
682 views
0 votes
1 answer

Create an empty array

You don't have to. The size of ...READ MORE

Jun 7, 2018 in Python by Hamartia's Mask
• 1,580 points
498 views