Commit 44c3ceb8 authored by Georg Brandl's avatar Georg Brandl

#8267: Use sorted() to get a sorted list of dict keys.

parent a81eae1f
...@@ -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::
......
...@@ -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::
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment