Common Questions
This is a list of common questions within the Python tag. Each question includes some canonical SO questions that can be used to close-vote any new questions that match. If you have any suggestions then please come see us in chat.
- Each space separated value is a separate search term.
- Terms are ANDed together.
- [Brackets] indicate a tag term.
is:draft
shows only draft posts.is:community
shows only community posts.
- 1 - 30 of 30
- 1
Sometimes it is useful to access both the current and next item when iterating over a list. |
A mutable object is modified in a loop and appended to a list. The OP is surprised that all of the list items are duplicates of the last appended object. |
The asker does |
An |
Create a single executable (exe) from a script, package, or other project. A common question when using Windows. |
Multiplying a list creates a shallow copy, not a deep copy, so any mutable objects in the list are then shared. Solution is to use a list comprehension to create separate objects. |
listdir() returns just the file names; you have to |
How can I extract different parts of a string or list using slicing notation or the |
Unpacking assignment from a list, tuple, map, etc. into separate names |
Specifying the type of items contained within a homogeneous list (or other collection) for the purpose of type hinting in PyCharm and other IDEs |
|
Zip can be used to iterate over multiple lists at the same time. In Python 3.x a generator is used whilst in Python 2.x a new list of tuples is created, as such itertools.izip may be a better choice. |
Python throws an error if you modify the |
“Astonishing” behaviour of default mutable arguments: |
A single string or other object, possibly in parentheses, is passed as the second argument to |
How to remove items from a list while iterating over the same list without skipping elements. |
Flask provides the |
Why does id({}) == id({}) and id([]) == id([]) in CPython? |
Why do my variables disappear when I quit and restart? What format should I use for saving? |
The result set of a single column query is a list of tuples, instead of a list |
|
Sorting a list of version strings, eg |
How to split a single list into multiple lists with a fixed (maximum) size? |
I have a |
A typo like |
When using |
The terminology makes finding a canonical “That’s a list / dict / etc. comprehension” question hard. |
|
- 1 - 30 of 30
- 1