Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
981a9185
Commit
981a9185
authored
Nov 13, 2003
by
Andrew M. Kuchling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Various edits
parent
b845ef05
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
7 deletions
+9
-7
Doc/whatsnew/whatsnew24.tex
Doc/whatsnew/whatsnew24.tex
+9
-7
No files found.
Doc/whatsnew/whatsnew24.tex
View file @
981a9185
...
...
@@ -104,8 +104,8 @@ using a \var{key} parameter. Using \var{key} results in calling the
\method
{
lower()
}
method once for each element in the list while using
\var
{
cmp
}
will call the method twice for each comparison.
Note, f
or simple key functions and comparison functions, it is often
possible to avoid
the
\keyword
{
lambda
}
expression by using an unbound
F
or simple key functions and comparison functions, it is often
possible to avoid
a
\keyword
{
lambda
}
expression by using an unbound
method instead. For example, the above case-insensitive sort is best
coded as:
...
...
@@ -120,10 +120,11 @@ The \var{reverse} parameter should have a Boolean value. If the value is
of
\code
{
L.sort(lambda x,y: cmp(y.score, x.score))
}
, you can now write:
\code
{
L.sort(key = lambda x: x.score, reverse=True)
}
.
The results of sorting are now guaranteed to be stable. This means that
two entries with equal keys will be returned in the same order as
they were input.
The results of sorting are now guaranteed to be stable. This means
that two entries with equal keys will be returned in the same order as
they were input. For example, you can sort a list of people by name,
and then sort the list by age, resulting in a list sorted by age where
people with the same age are in name-sorted order.
\item
The list type gained a
\method
{
sorted(iterable)
}
method that works
like the in-place
\method
{
sort()
}
method but has been made suitable for
...
...
@@ -143,6 +144,7 @@ use in expressions. The differences are:
>>> list.sorted('Monte Python') # any iterable may be an input
[' ', 'M', 'P', 'e', 'h', 'n', 'n', 'o', 'o', 't', 't', 'y']
>>> colormap = dict(red=1, blue=2, green=3, black=4, yellow=5)
>>> # Lists the contents of the dict sorted by key values
>>> for k, v in list.sorted(colormap.iteritems()):
... print k, v
...
...
...
@@ -293,6 +295,6 @@ changes to your code:
The author would like to thank the following people for offering
suggestions, corrections and assistance with various drafts of this
article: .
article:
Raymond Hettinger
.
\end{document}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment