summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorAndrew M. Kuchling <amk@amk.ca>2003-11-08 15:58:49 (GMT)
committerAndrew M. Kuchling <amk@amk.ca>2003-11-08 15:58:49 (GMT)
commit1a420251cfe1a2cd967d9800bf34c72e09a18d20 (patch)
tree363fa00d8c33cf14c81f692fc6b3b31e06f0f904 /Doc
parentaf28e4b66b0415aa14396f77ae53f355d6eeae97 (diff)
downloadcpython-1a420251cfe1a2cd967d9800bf34c72e09a18d20.zip
cpython-1a420251cfe1a2cd967d9800bf34c72e09a18d20.tar.gz
cpython-1a420251cfe1a2cd967d9800bf34c72e09a18d20.tar.bz2
Add some recent changes
Diffstat (limited to 'Doc')
-rw-r--r--Doc/whatsnew/whatsnew24.tex47
1 files changed, 46 insertions, 1 deletions
diff --git a/Doc/whatsnew/whatsnew24.tex b/Doc/whatsnew/whatsnew24.tex
index aa64b86..2f80d89 100644
--- a/Doc/whatsnew/whatsnew24.tex
+++ b/Doc/whatsnew/whatsnew24.tex
@@ -27,8 +27,33 @@ rationale, refer to the PEP for a particular new feature.
%======================================================================
+\section{PEP 322: Reverse Iteration}
-% Large, PEP-level features and changes should be described here.
+A new built-in function, \function{reversed(seq)}, takes a sequence
+and returns an iterator that returns the elements of the sequence
+in reverse order.
+
+\begin{verbatim}
+>>> for i in reversed([1,2,3]):
+... print i
+...
+3
+2
+1
+\end{verbatim}
+
+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()}.
+
+\begin{verbatim}
+>>> input = open('/etc/passwd', 'r')
+>>> for line in reversed(list(input)):
+... print line
+...
+root:*:0:0:System Administrator:/var/root:/bin/tcsh
+ ...
+\end{verbatim}
%======================================================================
@@ -76,6 +101,23 @@ The \var{reverse} parameter should have a Boolean value. If the value is
of \code{L.sort() ; L.reverse()}, you can now write
\code{L.sort(reverse=True)}.
+\item The list type gained a \method{sorted(iterable)} method that
+returns the elements of the iterable as a sorted list. It also accepts
+the \var{cmp}, \var{key}, and \var{reverse} keyword arguments, same as
+the \method{sort()} method. An example usage:
+
+\begin{verbatim}
+>>> L = [9,7,8,3,2,4,1,6,5]
+>>> list.sorted(L)
+[1, 2, 3, 4, 5, 6, 7, 8, 9]
+>>> L
+[9, 7, 8, 3, 2, 4, 1, 6, 5]
+>>>
+\end{verbatim}
+
+Note that the original list is unchanged; the list returned by
+\method{sorted()} is a newly-created one.
+
\item The \function{zip()} built-in function and \function{itertools.izip()} now return an empty list
instead of raising a \exception{TypeError} exception if called
with no arguments.
@@ -114,6 +156,9 @@ details.
supports transparency, this makes it possible to use a transparent background.
(Contributed by J\"org Lehmann.)
+\item The \module{heapq} module is no longer implemented in Python,
+ having been converted into C.
+
\item The \module{random} module has a new method called \method{getrandbits(N)}
which returns an N-bit long integer.