14. Cheat Grids
Fast-reference tables to recall properties and complexities at a glance.
Mutability & Hashability
| Type |
Mutable? |
Hashable? |
Usable as dict key? |
| int |
No |
Yes |
Yes |
| float |
No |
Yes |
Yes |
| bool |
No |
Yes |
Yes |
| str |
No |
Yes |
Yes |
| tuple |
No |
Yes (if all items hashable) |
Yes |
| bytes |
No |
Yes |
Yes |
| frozenset |
No |
Yes |
Yes |
| list |
Yes |
No |
No |
| dict |
Yes |
No |
No |
| set |
Yes |
No |
No |
| bytearray |
Yes |
No |
No |
Common Big-O (average cases)
| Operation |
Big-O |
| Index by position |
O(1) |
| Search (x in list) |
O(n) |
| Append |
O(1) amort. |
| Insert/Delete at end |
O(1) amort. |
| Insert/Delete at beginning |
O(n) |
| Slice copy (lst[:]) |
O(n) |
| Sort |
O(n log n) |
| Operation |
Big-O (avg) |
| Get/Set/Delete by key |
O(1) |
| Membership (k in d) |
O(1) |
| Operation |
Big-O (avg) |
| Add/Remove/Contains |
O(1) |
| Union/Diff/Symmetric diff (A,B) |
O( |
A |
+ |
B |
) |
| Intersection (A ∩ B) |
O(min( |
A |
, |
B |
)) |