Lists
- Ordered and mutable
- Can be heterogenous
- Used for data that’s dynamic
- Defined with square brackets
List Comprehensions
- Offers a shorter syntax when you want to create a list based on another list.
- IE: creating a list of strings from a list of numbers
- Can be used to
map
and filter
lists.
Map
- List comprehensions can be used to map lists, which convert some
T
to another value, U
.
- IE:
list[str]
→ list[int]
Filter
- List comprehensions can also be used to filter lists, which remove values from a list based on a predicate (a function that returns a boolean)
Tuple
- Ordered and immutable
- Can be heterogenous
- Used for fixed data/records
Unpacking
- Since lists and tuples are both iterators, they’re able to be unpacked.
- Unpacking offers a way to assign variables from values within an iterator.
- IE: assigning
x
and y
variables from a coordinate
- It can be used within loops.
- IE: looping over a list of coordinates, you could unpack those values.