File: list_operations.rst

package info (click to toggle)
mypy 0.812-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 18,596 kB
  • sloc: python: 74,869; cpp: 11,212; ansic: 3,935; makefile: 238; sh: 13
file content (62 lines) | stat: -rw-r--r-- 879 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
.. _list-ops:

Native list operations
======================

These ``list`` operations have fast, optimized implementations. Other
list operations use generic implementations that are often slower.

Construction
------------

Construct list with specific items:

* ``[item0, ..., itemN]``

Construct list from iterable:

* ``list(x: Iterable)``

List comprehensions:

* ``[... for ... in ...]``
* ``[... for ... in ... if ...]``

Operators
---------

Get item by integer index:

* ``lst[n]``

Slicing:

* ``lst[n:m]``, ``lst[n:]``, ``lst[:m]``, ``lst[:]``

Repeat list ``n`` times:

* ``lst * n``, ``n * lst``

Statements
----------

Set item by integer index:

* ``lst[n] = x``

For loop over a list:

* ``for item in lst:``

Methods
-------

* ``lst.append(item)``
* ``lst.extend(x: Iterable)``
* ``lst.pop()``
* ``lst.count(item)``

Functions
---------

* ``len(lst: list)``