summaryrefslogtreecommitdiffstats
path: root/Doc/whatsnew
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2003-11-12 16:39:30 (GMT)
committerRaymond Hettinger <python@rcn.com>2003-11-12 16:39:30 (GMT)
commitbc3cba2881c4c99fa7cffe7c5bb46b596857f3d6 (patch)
tree0805ecdecdf3509d101d274536735a046b8ebf04 /Doc/whatsnew
parent607c00f7923d59e71066185e3af86056ed1e6b20 (diff)
downloadcpython-bc3cba2881c4c99fa7cffe7c5bb46b596857f3d6.zip
cpython-bc3cba2881c4c99fa7cffe7c5bb46b596857f3d6.tar.gz
cpython-bc3cba2881c4c99fa7cffe7c5bb46b596857f3d6.tar.bz2
Explain the advantages of reversed.
Diffstat (limited to 'Doc/whatsnew')
-rw-r--r--Doc/whatsnew/whatsnew24.tex9
1 files changed, 6 insertions, 3 deletions
diff --git a/Doc/whatsnew/whatsnew24.tex b/Doc/whatsnew/whatsnew24.tex
index 68742a8..23c3431 100644
--- a/Doc/whatsnew/whatsnew24.tex
+++ b/Doc/whatsnew/whatsnew24.tex
@@ -34,7 +34,7 @@ and returns an iterator that returns the elements of the sequence
in reverse order.
\begin{verbatim}
->>> for i in reversed([1,2,3]):
+>>> for i in reversed(xrange(1,4)):
... print i
...
3
@@ -42,9 +42,12 @@ in reverse order.
1
\end{verbatim}
+Compared to extended slicing, \code{range(1,4)[::-1]}, \function{reversed()}
+is easier to read, runs faster, and uses substantially less memory.
+
Note that \function{reversed()} only accepts sequences, not arbitrary
-iterators. If you want to reverse an iterator, convert it to
-a list or tuple with \function{list()} or \function{tuple()}.
+iterators. If you want to reverse an iterator, first convert it to
+a list with \function{list()}.
\begin{verbatim}
>>> input = open('/etc/passwd', 'r')