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
44c3ceb8
Commit
44c3ceb8
authored
Oct 15, 2010
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#8267: Use sorted() to get a sorted list of dict keys.
parent
a81eae1f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
5 deletions
+5
-5
Doc/tutorial/controlflow.rst
Doc/tutorial/controlflow.rst
+3
-3
Doc/tutorial/datastructures.rst
Doc/tutorial/datastructures.rst
+2
-2
No files found.
Doc/tutorial/controlflow.rst
View file @
44c3ceb8
...
@@ -431,9 +431,9 @@ function like this::
...
@@ -431,9 +431,9 @@ function like this::
print "-- I'm sorry, we're all out of", kind
print "-- I'm sorry, we're all out of", kind
for arg in arguments: print arg
for arg in arguments: print arg
print "-" * 40
print "-" * 40
keys =
keywords.keys(
)
keys =
sorted(keywords.keys()
)
keys.sort()
for kw in keys:
for kw in keys:
print kw, ":", keywords[kw]
print kw, ":", keywords[kw]
It could be called like this::
It could be called like this::
...
...
Doc/tutorial/datastructures.rst
View file @
44c3ceb8
...
@@ -481,8 +481,8 @@ using a non-existent key.
...
@@ -481,8 +481,8 @@ using a non-existent key.
The :meth:`keys` method of a dictionary object returns a list of all the keys
The :meth:`keys` method of a dictionary object returns a list of all the keys
used in the dictionary, in arbitrary order (if you want it sorted, just apply
used in the dictionary, in arbitrary order (if you want it sorted, just apply
the :
meth:`sort` method to the list of keys). To check whether a single key is
the :
func:`sorted` function to it). To check whether a single key is in the
in the
dictionary, use the :keyword:`in` keyword.
dictionary, use the :keyword:`in` keyword.
Here is a small example using a dictionary::
Here is a small example using a dictionary::
...
...
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