dict_operations.rst 870 B

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