|
|
@ -43,18 +43,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 |
|
|
|
>>> from collections import Counter |
|
|
|