diff options
author | Georg Brandl <georg@python.org> | 2010-10-15 15:31:09 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2010-10-15 15:31:09 (GMT) |
commit | 44c3ceb8aca1bc1bbb6de97a69fedfef360e590a (patch) | |
tree | 9b62d9c1aa1dac3ef50d43bab59c1a697fcfc880 /Doc/tutorial | |
parent | a81eae1fd71eed670d1c28bf940ea99b4bfa2335 (diff) | |
download | cpython-44c3ceb8aca1bc1bbb6de97a69fedfef360e590a.zip cpython-44c3ceb8aca1bc1bbb6de97a69fedfef360e590a.tar.gz cpython-44c3ceb8aca1bc1bbb6de97a69fedfef360e590a.tar.bz2 |
#8267: Use sorted() to get a sorted list of dict keys.
Diffstat (limited to 'Doc/tutorial')
-rw-r--r-- | Doc/tutorial/controlflow.rst | 6 | ||||
-rw-r--r-- | Doc/tutorial/datastructures.rst | 4 |
2 files changed, 5 insertions, 5 deletions
diff --git a/Doc/tutorial/controlflow.rst b/Doc/tutorial/controlflow.rst index a9247cd..a30d49c 100644 --- a/Doc/tutorial/controlflow.rst +++ b/Doc/tutorial/controlflow.rst @@ -431,9 +431,9 @@ function like this:: print "-- I'm sorry, we're all out of", kind for arg in arguments: print arg print "-" * 40 - keys = keywords.keys() - keys.sort() - for kw in keys: print kw, ":", keywords[kw] + keys = sorted(keywords.keys()) + for kw in keys: + print kw, ":", keywords[kw] It could be called like this:: diff --git a/Doc/tutorial/datastructures.rst b/Doc/tutorial/datastructures.rst index dfc2b33..cbf3491 100644 --- a/Doc/tutorial/datastructures.rst +++ b/Doc/tutorial/datastructures.rst @@ -481,8 +481,8 @@ using a non-existent key. 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 -the :meth:`sort` method to the list of keys). To check whether a single key is -in the dictionary, use the :keyword:`in` keyword. +the :func:`sorted` function to it). To check whether a single key is in the +dictionary, use the :keyword:`in` keyword. Here is a small example using a dictionary:: |