list_operations.rst 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. .. _list-ops:
  2. Native list operations
  3. ======================
  4. These ``list`` operations have fast, optimized implementations. Other
  5. list operations use generic implementations that are often slower.
  6. Construction
  7. ------------
  8. Construct list with specific items:
  9. * ``[item0, ..., itemN]``
  10. Construct empty list:
  11. * ``[]``
  12. * ``list()``
  13. Construct list from iterable:
  14. * ``list(x: Iterable)``
  15. List comprehensions:
  16. * ``[... for ... in ...]``
  17. * ``[... for ... in ... if ...]``
  18. Operators
  19. ---------
  20. * ``lst[n]`` (get item by integer index)
  21. * ``lst[n:m]``, ``lst[n:]``, ``lst[:m]``, ``lst[:]`` (slicing)
  22. * ``lst * n``, ``n * lst``
  23. * ``obj in lst``
  24. Statements
  25. ----------
  26. Set item by integer index:
  27. * ``lst[n] = x``
  28. For loop over a list:
  29. * ``for item in lst:``
  30. Methods
  31. -------
  32. * ``lst.append(obj)``
  33. * ``lst.extend(x: Iterable)``
  34. * ``lst.insert(index, obj)``
  35. * ``lst.pop(index=-1)``
  36. * ``lst.remove(obj)``
  37. * ``lst.count(obj)``
  38. * ``lst.index(obj)``
  39. * ``lst.reverse()``
  40. * ``lst.sort()``
  41. Functions
  42. ---------
  43. * ``len(lst: list)``