|
|
@ -27,12 +27,9 @@ List |
|
|
|
sum(<list>) |
|
|
|
sorted_by_second = sorted(<list>, key=lambda el: el[1]) |
|
|
|
flattened_list = [item for sublist in <list> for item in sublist] |
|
|
|
list(<str>) # Creates list of chars. |
|
|
|
``` |
|
|
|
|
|
|
|
```python |
|
|
|
>>> list('ABC') |
|
|
|
['A', 'B', 'C'] |
|
|
|
``` |
|
|
|
|
|
|
|
Dictionary |
|
|
|
---------- |
|
|
@ -43,17 +40,18 @@ Dictionary |
|
|
|
<dict>.update(<dict>) |
|
|
|
``` |
|
|
|
|
|
|
|
```python |
|
|
|
>>> a = [('x', 4), ('y', 5)] |
|
|
|
>>> dict(a) |
|
|
|
{'x': 4, 'y': 5} |
|
|
|
``` |
|
|
|
|
|
|
|
```python |
|
|
|
collections.defaultdict(<type>) # Creates a dictionary with default values. |
|
|
|
dict(zip(keys, values)) # Initiates a dict from two lists. |
|
|
|
{k: v for k, v in <dict>.items() if k in <list>} # Filters a dict by keys. |
|
|
|
``` |
|
|
|
|
|
|
|
```python |
|
|
|
>>> a = [('x', 4), ('y', 5)] |
|
|
|
>>> dict(a) |
|
|
|
{'x': 4, 'y': 5} |
|
|
|
``` |
|
|
|
|
|
|
|
### Counter |
|
|
|
```python |
|
|
|