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

Skip to content

Commit a95e87a

Browse files
committed
Guido grants a Christmas wish:
sorted() becomes a regular function instead of a classmethod.
1 parent b606b3d commit a95e87a

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

Doc/tut/tut.tex

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2211,6 +2211,20 @@ \section{Looping Techniques \label{loopidioms}}
22112211
1
22122212
\end{verbatim}
22132213

2214+
To loop over a sequence in sorted order, use the \function{sorted()}
2215+
function which returns a new sorted list while leaving the source
2216+
unaltered.
2217+
2218+
\begin{verbatim}
2219+
>>> basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana']
2220+
>>> for f in sorted(set(basket)):
2221+
... print f
2222+
...
2223+
apple
2224+
banana
2225+
orange
2226+
pear
2227+
\end{verbatim}
22142228

22152229
\section{More on Conditions \label{conditions}}
22162230

0 commit comments

Comments
 (0)