| 1 |
.. _dict-ops: |
| 2 |
|
| 3 |
Native dict operations |
| 4 |
====================== |
| 5 |
|
| 6 |
These ``dict`` operations have fast, optimized implementations. Other |
| 7 |
dictionary operations use generic implementations that are often slower. |
| 8 |
|
| 9 |
Construction |
| 10 |
------------ |
| 11 |
|
| 12 |
Construct dict from keys and values: |
| 13 |
|
| 14 |
* ``{key: value, ...}`` |
| 15 |
|
| 16 |
Construct empty dict: |
| 17 |
|
| 18 |
* ``{}`` |
| 19 |
* ``dict()`` |
| 20 |
|
| 21 |
Construct dict from another object: |
| 22 |
|
| 23 |
* ``dict(d: dict)`` |
| 24 |
* ``dict(x: Iterable)`` |
| 25 |
|
| 26 |
Dict comprehensions: |
| 27 |
|
| 28 |
* ``{...: ... for ... in ...}`` |
| 29 |
* ``{...: ... for ... in ... if ...}`` |
| 30 |
|
| 31 |
Operators |
| 32 |
--------- |
| 33 |
|
| 34 |
* ``d[key]`` |
| 35 |
* ``value in d`` |
| 36 |
|
| 37 |
Statements |
| 38 |
---------- |
| 39 |
|
| 40 |
* ``d[key] = value`` |
| 41 |
* ``for key in d:`` |
| 42 |
|
| 43 |
Methods |
| 44 |
------- |
| 45 |
|
| 46 |
* ``d.get(key)`` |
| 47 |
* ``d.get(key, default)`` |
| 48 |
* ``d.keys()`` |
| 49 |
* ``d.values()`` |
| 50 |
* ``d.items()`` |
| 51 |
* ``d.copy()`` |
| 52 |
* ``d.clear()`` |
| 53 |
* ``d.setdefault(key)`` |
| 54 |
* ``d.setdefault(key, value)`` |
| 55 |
* ``d1.update(d2: dict)`` |
| 56 |
* ``d.update(x: Iterable)`` |
| 57 |
|
| 58 |
Functions |
| 59 |
--------- |
| 60 |
|
| 61 |
* ``len(d: dict)`` |