Dictionaries
Are:
- mutable
- keys must be hashable
- this meaning
functions
can actually be keys
- this meaning
- have fun methods like
pop()
andpopitem()
for removing keys - support nesting
- don’t support nested membership tests
|
|
Sets
Oh. boy. First class support for sets 🤩 wow, I’m so excited!
Operator | Method Name | Note |
---|---|---|
| | union | Is a set of all elements in either set. |
& | intersection | Is a set of all the common elements between either set. |
- | difference | Is a set of all elements that are in x1 but not in x2. |
^ | symmetric_difference | Is a set of all elements in either x or x2, but not both. |
<= | issubset | If every element of x1 is in x2. |
< | If proper subset, like subset, but only if it is not identical to itself. | |
>= | issuperset | If x1 contains every element of x2. |
> | If proper superset, like superset, but only if it is not identical to itself. | |
|= | update | Add to x1 any elements in x2 that x1 does not already have. |
&= | intersection_update | Update x1 to retain only elements found in both x1 and x2 |
-= | difference_update | Update x1, removing elements found in x2 |
^= | symmetric_difference_update | Update x1, retaining elements found in either x1 or x2, but not both. |
frozenset
type is immutable, so it can be used as a dictionary key.
The biggest value of using sets is their speed, they’re way faster to iterate through than lists and tuples.