Browse Source

Dict

pull/3/head
Jure Šorn 6 years ago
parent
commit
404b3ccdbb
1 changed files with 7 additions and 9 deletions
  1. 16
      README.md

16
README.md

@ -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

Loading…
Cancel
Save