English
Summary
Conclusions
A list is convenient for a mutable sequence, a tuple for a fixed record, a set for uniqueness, and a dictionary for access by key. Counter, defaultdict, and deque simplify common operations when their behavior matches the problem's rules. Copying, order, and hashability are part of the program's contract.
Self-check questions
- Which properties distinguish lists, tuples, sets, and dictionaries?
- How does an out-of-bounds index differ from an out-of-bounds slice?
- How does a negative step work, and why is
step=0prohibited? - How does
appenddiffer fromextend? - What do
sort,sorted, andpopreturn? - Why is sorting by a tuple of keys convenient for a ranking?
- How do you build independent matrix rows?
- What does
copycopy, and what doesdeepcopycopy? - Why is a tuple containing a list unsuitable as a dictionary key?
- How do set difference and symmetric difference differ?
- When do
getandsetdefaulthave different effects on a dictionary? - Which collection changes are dangerous during iteration?
- How does
Counter.subtractdiffer from the subtraction operator? - What are
maxlen,OrderedDict, andChainMapused for? - Why is
insortO(n) even though finding the position is O(log n)?
Useful links
- https://docs.python.org/3.14/tutorial/datastructures.html
- https://docs.python.org/3.14/library/stdtypes.html
- https://docs.python.org/3.14/library/collections.html
- https://docs.python.org/3.14/library/copy.html
- https://docs.python.org/3.14/library/heapq.html
- https://docs.python.org/3.14/library/bisect.html