Введение в Python
Теория: Типы-коллекции
Полный доступ к материалам
Collections in Python
Lists, Tuples, Dictionaries and Sets
List
- Square brackets syntax
- Mutable
- Get value by index (from zero)
Tuple
- Round brackets syntax
- Immutable
- A little bit faster than list
Dictionary
- Key-value storage
- Mutable
- O(1) access complexity
- Any immutable value as a key
Set
- Stores unique values
- Based on hashes
- Only immutable values
- Supports subtractions, intersections, etc
Some notes
Common operations
- Check if the collection has an element
- Slices
- Iteration
- Unpacking
- Coerce to other type
In
Slices
Iteration
Unpacking Lists and Tuples
Convert collections
Nested collections
Tips