From: Raymond Hettinger Date: Wed, 17 Dec 2003 21:38:26 +0000 (+0000) Subject: Guido grants a Christmas wish: X-Git-Tag: v2.4a1~1075 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a95e87a48822ac459fddb2e81c3f7583a70a56e3;p=thirdparty%2FPython%2Fcpython.git Guido grants a Christmas wish: sorted() becomes a regular function instead of a classmethod. --- diff --git a/Doc/tut/tut.tex b/Doc/tut/tut.tex index b03f6830818e..cbec92ca6299 100644 --- a/Doc/tut/tut.tex +++ b/Doc/tut/tut.tex @@ -2211,6 +2211,20 @@ function. 1 \end{verbatim} +To loop over a sequence in sorted order, use the \function{sorted()} +function which returns a new sorted list while leaving the source +unaltered. + +\begin{verbatim} +>>> basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana'] +>>> for f in sorted(set(basket)): +... print f +... +apple +banana +orange +pear +\end{verbatim} \section{More on Conditions \label{conditions}}