Browse Source

Dict

pull/27/head
Jure Šorn 6 years ago
parent
commit
a51363ab5f
1 changed files with 5 additions and 5 deletions
  1. 10
      README.md

10
README.md

@ -65,15 +65,15 @@ Dictionary
```python ```python
value = <dict>.get(key, default=None) # Returns default if key does not exist. value = <dict>.get(key, default=None) # Returns default if key does not exist.
value = <dict>.setdefault(key, default=None) # Same, but also adds default to dict. value = <dict>.setdefault(key, default=None) # Same, but also adds default to dict.
<dict> = collections.defaultdict(<type>) # Creates a dictionary with default value of type.
<dict> = collections.defaultdict(lambda: 1) # Creates a dictionary with default value 1.
<dict> = collections.defaultdict(<type>) # Creates a dict with default value of type.
<dict> = collections.defaultdict(lambda: 1) # Creates a dict with default value 1.
``` ```
```python ```python
<dict>.update(<dict>) # Or: dict_a = {**dict_a, **dict_b}. <dict>.update(<dict>) # Or: dict_a = {**dict_a, **dict_b}.
<dict> = dict(<collection>) # Initiates a dict from coll. of key-value pairs.
<dict> = dict(zip(keys, values)) # Initiates a dict from two collections.
<dict> = dict.fromkeys(keys [, value]) # Initiates a dict from collection of keys.
<dict> = dict(<collection>) # Inits a dict from coll. of key-value pairs.
<dict> = dict(zip(keys, values)) # Inits a dict from two collections.
<dict> = dict.fromkeys(keys [, value]) # Inits a dict from collection of keys.
``` ```
```python ```python

Loading…
Cancel
Save