Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1a42025

Browse files
committed
Add some recent changes
1 parent af28e4b commit 1a42025

1 file changed

Lines changed: 46 additions & 1 deletion

File tree

Doc/whatsnew/whatsnew24.tex

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,33 @@
2727

2828

2929
%======================================================================
30+
\section{PEP 322: Reverse Iteration}
3031

31-
% Large, PEP-level features and changes should be described here.
32+
A new built-in function, \function{reversed(seq)}, takes a sequence
33+
and returns an iterator that returns the elements of the sequence
34+
in reverse order.
35+
36+
\begin{verbatim}
37+
>>> for i in reversed([1,2,3]):
38+
... print i
39+
...
40+
3
41+
2
42+
1
43+
\end{verbatim}
44+
45+
Note that \function{reversed()} only accepts sequences, not arbitrary
46+
iterators. If you want to reverse an iterator, convert it to
47+
a list or tuple with \function{list()} or \function{tuple()}.
48+
49+
\begin{verbatim}
50+
>>> input = open('/etc/passwd', 'r')
51+
>>> for line in reversed(list(input)):
52+
... print line
53+
...
54+
root:*:0:0:System Administrator:/var/root:/bin/tcsh
55+
...
56+
\end{verbatim}
3257

3358

3459
%======================================================================
@@ -76,6 +101,23 @@ \section{Other Language Changes}
76101
of \code{L.sort() ; L.reverse()}, you can now write
77102
\code{L.sort(reverse=True)}.
78103

104+
\item The list type gained a \method{sorted(iterable)} method that
105+
returns the elements of the iterable as a sorted list. It also accepts
106+
the \var{cmp}, \var{key}, and \var{reverse} keyword arguments, same as
107+
the \method{sort()} method. An example usage:
108+
109+
\begin{verbatim}
110+
>>> L = [9,7,8,3,2,4,1,6,5]
111+
>>> list.sorted(L)
112+
[1, 2, 3, 4, 5, 6, 7, 8, 9]
113+
>>> L
114+
[9, 7, 8, 3, 2, 4, 1, 6, 5]
115+
>>>
116+
\end{verbatim}
117+
118+
Note that the original list is unchanged; the list returned by
119+
\method{sorted()} is a newly-created one.
120+
79121
\item The \function{zip()} built-in function and \function{itertools.izip()} now return an empty list
80122
instead of raising a \exception{TypeError} exception if called
81123
with no arguments.
@@ -114,6 +156,9 @@ \section{New, Improved, and Deprecated Modules}
114156
supports transparency, this makes it possible to use a transparent background.
115157
(Contributed by J\"org Lehmann.)
116158

159+
\item The \module{heapq} module is no longer implemented in Python,
160+
having been converted into C.
161+
117162
\item The \module{random} module has a new method called \method{getrandbits(N)}
118163
which returns an N-bit long integer.
119164

0 commit comments

Comments
 (0)