]> granicus.if.org Git - python/commitdiff
#8267: Use sorted() to get a sorted list of dict keys.
authorGeorg Brandl <georg@python.org>
Fri, 15 Oct 2010 15:31:09 +0000 (15:31 +0000)
committerGeorg Brandl <georg@python.org>
Fri, 15 Oct 2010 15:31:09 +0000 (15:31 +0000)
Doc/tutorial/controlflow.rst
Doc/tutorial/datastructures.rst

index a9247cd0b9a5769d900354cfdb7fce845f7be83f..a30d49cb10baeb9b6142a6f5e9c1bd76b583af2c 100644 (file)
@@ -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::
 
index dfc2b33bb9e979ea01a65a6ee78e5ec37ef9685a..cbf3491000cea02d68711b945915e1f5fa33d389 100644 (file)
@@ -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::