From a95e87a48822ac459fddb2e81c3f7583a70a56e3 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Wed, 17 Dec 2003 21:38:26 +0000 Subject: [PATCH] Guido grants a Christmas wish: sorted() becomes a regular function instead of a classmethod. --- Doc/tut/tut.tex | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Doc/tut/tut.tex b/Doc/tut/tut.tex index b03f6830818..cbec92ca629 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}}