Browse Source

Dict, json

pull/3/head
Jure Šorn 6 years ago
parent
commit
c144dc129f
1 changed files with 8 additions and 1 deletions
  1. 9
      README.md

9
README.md

@ -52,6 +52,7 @@ Dictionary
```python
collections.defaultdict(<type>) # Creates a dictionary with default values.
collections.OrderedDict() # Creates ordered dictionary.
dict(<list>) # Initiates a dict from list of key/value pairs.
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.
@ -528,7 +529,13 @@ import json
### Serialization
```python
<str> = json.dumps(<object>, ensure_ascii=True, indent=None)
<object> = json.loads(<str>)
<dict> = json.loads(<str>)
```
#### To preserve order:
```python
from collections import OrderedDict
<dict> = json.loads(<str>, object_pairs_hook=OrderedDict)
```
### Read File

Loading…
Cancel
Save