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

Skip to content

Commit 35f2b05

Browse files
committed
Add various items
1 parent 852fe06 commit 35f2b05

1 file changed

Lines changed: 60 additions & 4 deletions

File tree

Doc/whatsnew/whatsnew24.tex

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@
2020

2121
This article doesn't attempt to provide a complete specification of
2222
the new features, but instead provides a convenient overview. For
23-
full details, you should refer to the documentation for Python 2.4.
24-
% add hyperlink when the documentation becomes available online.
23+
full details, you should refer to the documentation for Python 2.4,
24+
such as the \citetitle[../lib/lib.html]{Python Library Reference} and
25+
the \citetitle[../ref/ref.html]{Python Reference Manual}.
2526
If you want to understand the complete implementation and design
2627
rationale, refer to the PEP for a particular new feature.
2728

29+
2830
%======================================================================
2931
\section{PEP 218: Built-In Set Objects}
3032

@@ -67,11 +69,18 @@ \section{PEP 218: Built-In Set Objects}
6769
as a member of another set. Accordingly, it does not have methods
6870
like \method{add()} and \method{remove()} which could alter its contents.
6971

72+
% XXX what happens to the sets module?
73+
7074
\begin{seealso}
7175
\seepep{218}{Adding a Built-In Set Object Type}{Originally proposed by
7276
Greg Wilson and ultimately implemented by Raymond Hettinger.}
7377
\end{seealso}
7478

79+
%======================================================================
80+
\section{PEP 237: Unifying Long Integers and Integers}
81+
82+
XXX write this.
83+
7584
%======================================================================
7685
\section{PEP 322: Reverse Iteration}
7786

@@ -122,6 +131,16 @@ \section{Other Language Changes}
122131
\method{center()} now take an optional argument for specifying a
123132
fill character other than a space.
124133

134+
\item Strings also gained an \method{rsplit()} method that
135+
works like the \method{split()} method but splits from the end of the string.
136+
137+
\begin{verbatim}
138+
>>> 'a b c'.split(None, 1)
139+
['a', 'b c']
140+
>>> 'a b c'.rsplit(None, 1)
141+
['a b', 'c']
142+
\end{verbatim}
143+
125144
\item The \method{sort()} method of lists gained three keyword
126145
arguments, \var{cmp}, \var{key}, and \var{reverse}. These arguments
127146
make some common usages of \method{sort()} simpler. All are optional.
@@ -177,7 +196,7 @@ \section{Other Language Changes}
177196
and then sort the list by age, resulting in a list sorted by age where
178197
people with the same age are in name-sorted order.
179198

180-
\item There is a new builtin function \function{sorted(iterable)} that works
199+
\item There is a new built-in function \function{sorted(iterable)} that works
181200
like the in-place \method{list.sort()} method but has been made suitable
182201
for use in expressions. The differences are:
183202
\begin{itemize}
@@ -209,7 +228,6 @@ \section{Other Language Changes}
209228
210229
\end{verbatim}
211230

212-
213231
\item The \function{zip()} built-in function and \function{itertools.izip()}
214232
now return an empty list instead of raising a \exception{TypeError}
215233
exception if called with no arguments. This makes the functions more
@@ -312,10 +330,48 @@ \section{New, Improved, and Deprecated Modules}
312330
['a', 'b', 'r']
313331
\end{verbatim}
314332

333+
\item \module{itertools} also gained a function named \function{tee(\var{iterator}, \var{N})} that returns \var{N} independent iterators
334+
that replicate \var{iterator}. If \var{N} is omitted, the default is
335+
2.
336+
337+
\begin{verbatim}
338+
>>> L = [1,2,3]
339+
>>> i1, i2 = itertools.tee(L)
340+
>>> i1,i2
341+
(<itertools.tee object at 0x402c2080>, <itertools.tee object at 0x402c2090>)
342+
>>> list(i1)
343+
[1, 2, 3]
344+
>>> list(i2)
345+
[1, 2, 3]
346+
>\end{verbatim}
347+
348+
Note that \function{tee()} has to keep copies of the values returned
349+
by the iterator; in the worst case it may need to keep all of them.
350+
This should therefore be used carefully if \var{iterator}
351+
returns a very large stream of results.
352+
315353
\item A new \function{getsid()} function was added to the
316354
\module{posix} module that underlies the \module{os} module.
317355
(Contributed by J. Raynor.)
318356

357+
\item The \module{operator} module gained two new functions,
358+
\function{attrgetter(\var{attr})} and \function{itemgetter(\var{index})}.
359+
Both functions return callables that take a single argument and return
360+
the corresponding attribute or item; these callables are handy for use
361+
with \function{map()} or \function{list.sort()}. For example, here's a simple
362+
us
363+
364+
\begin{verbatim}
365+
>>> L = [('c', 2), ('d', 1), ('a', '4'), ('b', 3)]
366+
>>> map(operator.itemgetter(0), L)
367+
['c', 'd', 'a', 'b']
368+
>>> map(operator.itemgetter(1), L)
369+
[2, 1, '4', 3]
370+
>>> L.sort(key=operator.itemgetter(1)) # Sort list by second item in tuples
371+
>>> L
372+
[('d', 1), ('c', 2), ('b', 3), ('a', '4')]
373+
\end{verbatim}
374+
319375
\item The \module{random} module has a new method called \method{getrandbits(N)}
320376
which returns an N-bit long integer. This method supports the existing
321377
\method{randrange()} method, making it possible to efficiently generate

0 commit comments

Comments
 (0)