mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
AAdd item. (And so it beegins again.)
This commit is contained in:
parent
92e2495af6
commit
1cae3f57e7
1 changed files with 18 additions and 1 deletions
|
@ -37,7 +37,24 @@ Here are all of the changes that Python 2.5 makes to the core Python
|
||||||
language.
|
language.
|
||||||
|
|
||||||
\begin{itemize}
|
\begin{itemize}
|
||||||
\item TBD
|
|
||||||
|
\item The \function{min()} and \function{max()} built-in functions
|
||||||
|
gained a \code{key} keyword argument analogous to the \code{key}
|
||||||
|
argument for \function{sort()}. This argument supplies a function
|
||||||
|
that takes a single argument and is called for every value in the list;
|
||||||
|
\function{min()}/\function{max()} will return the element with the
|
||||||
|
smallest/largest return value from this function.
|
||||||
|
For example, to find the longest string in a list, you can do:
|
||||||
|
|
||||||
|
\begin{verbatim}
|
||||||
|
L = ['medium', 'longest', 'short']
|
||||||
|
# Prints 'longest'
|
||||||
|
print max(L, key=len)
|
||||||
|
# Prints 'short', because lexicographically 'short' has the largest value
|
||||||
|
print max(L)
|
||||||
|
\end{verbatim}
|
||||||
|
|
||||||
|
(Contributed by Steven Bethard and Raymond Hettinger.)
|
||||||
|
|
||||||
\end{itemize}
|
\end{itemize}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue