@@ -104,8 +104,8 @@ \section{Other Language Changes}
104104\method {lower()} method once for each element in the list while using
105105\var {cmp} will call the method twice for each comparison.
106106
107- Note, for simple key functions and comparison functions, it is often
108- possible to avoid the \keyword {lambda} expression by using an unbound
107+ For simple key functions and comparison functions, it is often
108+ possible to avoid a \keyword {lambda} expression by using an unbound
109109method instead. For example, the above case-insensitive sort is best
110110coded as:
111111
@@ -120,10 +120,11 @@ \section{Other Language Changes}
120120of \code {L.sort(lambda x,y: cmp(y.score, x.score))}, you can now write:
121121\code {L.sort(key = lambda x: x.score, reverse=True)}.
122122
123- The results of sorting are now guaranteed to be stable. This means that
124- two entries with equal keys will be returned in the same order as
125- they were input.
126-
123+ The results of sorting are now guaranteed to be stable. This means
124+ that two entries with equal keys will be returned in the same order as
125+ they were input. For example, you can sort a list of people by name,
126+ and then sort the list by age, resulting in a list sorted by age where
127+ people with the same age are in name-sorted order.
127128
128129\item The list type gained a \method {sorted(iterable)} method that works
129130like the in-place \method {sort()} method but has been made suitable for
@@ -143,6 +144,7 @@ \section{Other Language Changes}
143144>>> list.sorted('Monte Python') # any iterable may be an input
144145[' ', 'M', 'P', 'e', 'h', 'n', 'n', 'o', 'o', 't', 't', 'y']
145146>>> colormap = dict(red=1, blue=2, green=3, black=4, yellow=5)
147+ >>> # Lists the contents of the dict sorted by key values
146148>>> for k, v in list.sorted(colormap.iteritems()):
147149... print k, v
148150...
@@ -293,6 +295,6 @@ \section{Acknowledgements \label{acks}}
293295
294296The author would like to thank the following people for offering
295297suggestions, corrections and assistance with various drafts of this
296- article: .
298+ article: Raymond Hettinger .
297299
298300\end {document }
0 commit comments