]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Guido grants a Christmas wish:
authorRaymond Hettinger <python@rcn.com>
Wed, 17 Dec 2003 21:38:26 +0000 (21:38 +0000)
committerRaymond Hettinger <python@rcn.com>
Wed, 17 Dec 2003 21:38:26 +0000 (21:38 +0000)
  sorted() becomes a regular function instead of a classmethod.

Doc/tut/tut.tex

index b03f6830818e6370eb784410e643a4f5fbea5a48..cbec92ca6299c4ab583a31795e21bec01dfacc88 100644 (file)
@@ -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}}