@@ -14,33 +14,58 @@ hold/accumulate various objects.
14
14
Classes
15
15
-------
16
16
17
- .. class :: deque(iterable, maxlen[, flags ])
17
+ .. class :: deque(iterable, maxlen[, flag ])
18
18
19
- Deques (double-ended queues ) are a list-like container that support O(1)
20
- appends and pops from either side of the deque. New deques are created
21
- using the following arguments:
19
+ Deques (pronounced "deck" and short for " double-ended queue" ) are fixed length
20
+ list-like containers that support O(1) appends and pops from either side of the
21
+ deque. New deques are created using the following arguments:
22
22
23
- - *iterable * must be the empty tuple, and the new deque is created empty.
23
+ - *iterable * must be specified as an empty or non-empty iterable.
24
+ If the iterable is empty, the new deque is created empty. If the
25
+ iterable is not empty, the new deque is created with the items
26
+ from the iterable.
24
27
25
28
- *maxlen * must be specified and the deque will be bounded to this
26
29
maximum length. Once the deque is full, any new items added will
27
30
discard items from the opposite end.
28
31
29
- - The optional *flags * can be 1 to check for overflow when adding items.
32
+ - *flag * is optional and can be set to 1 to check for overflow when
33
+ adding items. If the deque is full and overflow checking is enabled,
34
+ an IndexError will be raised when adding items.
30
35
31
- As well as supporting ``bool `` and ``len ``, deque objects have the following
32
- methods:
36
+ Deque objects have the following methods:
33
37
34
38
.. method :: deque.append(x)
35
39
36
40
Add *x * to the right side of the deque.
37
41
Raises IndexError if overflow checking is enabled and there is no more room left.
38
42
43
+ .. method :: deque.appendleft(x)
44
+
45
+ Add *x * to the left side of the deque.
46
+ Raises IndexError if overflow checking is enabled and there is no more room left.
47
+
48
+ .. method :: deque.pop()
49
+
50
+ Remove and return an item from the right side of the deque.
51
+ Raises IndexError if no items are present.
52
+
39
53
.. method :: deque.popleft()
40
54
41
55
Remove and return an item from the left side of the deque.
42
56
Raises IndexError if no items are present.
43
57
58
+ .. method :: deque.extend(iterable)
59
+
60
+ Extend the right side of the deque by appending items from the *iterable * argument.
61
+ Raises IndexError if overflow checking is enabled and there is no more room left
62
+ for all of the items in *iterable *.
63
+
64
+ In addition to the above, deques support iteration, ``bool ``, ``len(d) ``, ``reversed(d) ``,
65
+ membership testing with the ``in `` operator, and subscript references like ``d[0] ``.
66
+ Note: Indexed access is O(1) at both ends but slows to O(n) in the middle of the deque,
67
+ so for fast random access use a ``list `` instead.
68
+
44
69
.. function :: namedtuple(name, fields)
45
70
46
71
This is factory function to create a new namedtuple type with a specific
0 commit comments