Lists and Tuples
- Lists. A list is an ordered, mutable sequence: append, insert, sort and slice at will.
- Tuples. A tuple is an immutable sequence: fixed at creation, hashable, and honest about data that should not change.
- Slicing. A slice like items[2:5] copies part of a sequence, and items[::-1] is the classic reversed copy.
Dictionaries and Sets
- Dictionaries. A dict maps keys to values with instant lookup: the data structure most Python programs are secretly made of.
- Dictionary methods. The get method reads a key with a default instead of raising KeyError when it is missing.
- Sets. A set stores unique values and answers membership instantly: deduplication is one constructor call.
Comprehensions and Collection Patterns
- List comprehensions. A comprehension builds a list in one readable line, transforming each item of a source sequence.
- Filtering comprehensions. Adding an if inside a comprehension filters while building: [n for n in nums if n > 0].
- Dict and set comprehensions. The same syntax with braces builds dicts and sets: {user.id: user for user in users} is a lookup table in one line.
Before and after this level
- Before: Level 2: Decisions & Loops: Conditions, Iteration and Loops, Writing Clear Program Flow.
- Next: Level 4: Functions & Scope: Functions, Parameters and Returns, Scope and Name Resolution, Functional Patterns and Lambdas.
In the app each of these ideas is taught and then asked back, and the level ends with a checkpoint and flashcards. See Checkpoints and flashcards.
Frequently asked questions
What does Python Level 3: Python Collections cover?
Lists and Tuples, Dictionaries and Sets, Comprehensions and Collection Patterns: 3 lessons and 9 ideas.
What should I know before this level?
The level before it, Level 2: Decisions & Loops, which covers Conditions, Iteration and Loops, Writing Clear Program Flow.