summaryrefslogtreecommitdiffstats
path: root/Doc/lib/libcollections.tex
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-03-01 23:16:22 (GMT)
committerRaymond Hettinger <python@rcn.com>2004-03-01 23:16:22 (GMT)
commit0a4977c2f3b8b3cd80f326f44e87076b2578b1b6 (patch)
tree25342a34c69da22a41fe9964852de92ab6c7ff8b /Doc/lib/libcollections.tex
parent786ea6bc23c26a0ec98d5cbc80633615f9fa8cb1 (diff)
downloadcpython-0a4977c2f3b8b3cd80f326f44e87076b2578b1b6.zip
cpython-0a4977c2f3b8b3cd80f326f44e87076b2578b1b6.tar.gz
cpython-0a4977c2f3b8b3cd80f326f44e87076b2578b1b6.tar.bz2
Replace left(), right(), and __reversed__() with the more general purpose
__getitem__() and __setitem__(). Simplifies the API, reduces the code size, adds flexibility, and makes deques work with bisect.bisect(), random.shuffle(), and random.sample().
Diffstat (limited to 'Doc/lib/libcollections.tex')
-rw-r--r--Doc/lib/libcollections.tex21
1 files changed, 6 insertions, 15 deletions
diff --git a/Doc/lib/libcollections.tex b/Doc/lib/libcollections.tex
index 2793095..14e3bf5 100644
--- a/Doc/lib/libcollections.tex
+++ b/Doc/lib/libcollections.tex
@@ -54,11 +54,6 @@ Deque objects support the following methods:
reversing the order of elements in the iterable argument.
\end{methoddesc}
-\begin{methoddesc}{left}{}
- Return leftmost element from the deque.
- If no elements are present, raises a \exception{IndexError}.
-\end{methoddesc}
-
\begin{methoddesc}{pop}{}
Remove and return an element from the right side of the deque.
If no elements are present, raises a \exception{IndexError}.
@@ -69,11 +64,6 @@ Deque objects support the following methods:
If no elements are present, raises a \exception{IndexError}.
\end{methoddesc}
-\begin{methoddesc}{right}{}
- Return the rightmost element from the deque.
- If no elements are present, raises a \exception{IndexError}.
-\end{methoddesc}
-
\begin{methoddesc}{rotate}{n}
Rotate the deque \var{n} steps to the right. If \var{n} is
negative, rotate to the left. Rotating one step to the right
@@ -81,8 +71,9 @@ Deque objects support the following methods:
\end{methoddesc}
In addition to the above, deques support iteration, pickling, \samp{len(d)},
-\samp{reversed(d)}, \samp{copy.copy(d)}, \samp{copy.deepcopy(d)}, and
-membership testing with the \keyword{in} operator.
+\samp{reversed(d)}, \samp{copy.copy(d)}, \samp{copy.deepcopy(d)},
+membership testing with the \keyword{in} operator, and subscript references
+such as \samp{d[-1]}.
Example:
@@ -106,11 +97,11 @@ deque(['f', 'g', 'h', 'i', 'j'])
'f'
>>> list(d) # list the contents of the deque
['g', 'h', 'i']
-
->>> d.left() # peek at leftmost item
+>>> d[0] # peek at leftmost item
'g'
->>> d.right() # peek at rightmost item
+>>> d[-1] # peek at rightmost item
'i'
+
>>> list(reversed(d)) # list the contents of a deque in reverse
['i', 'h', 'g']
>>> 'h' in d # search the deque