[Python-checkins] r85529 - in python/branches/release27-maint/Doc/tutorial: controlflow.rst datastructures.rst

georg.brandl python-checkins at python.org
Fri Oct 15 17:31:09 CEST 2010


Author: georg.brandl
Date: Fri Oct 15 17:31:09 2010
New Revision: 85529

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

Modified:
   python/branches/release27-maint/Doc/tutorial/controlflow.rst
   python/branches/release27-maint/Doc/tutorial/datastructures.rst

Modified: python/branches/release27-maint/Doc/tutorial/controlflow.rst
==============================================================================
--- python/branches/release27-maint/Doc/tutorial/controlflow.rst	(original)
+++ python/branches/release27-maint/Doc/tutorial/controlflow.rst	Fri Oct 15 17:31:09 2010
@@ -431,9 +431,9 @@
        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::
 

Modified: python/branches/release27-maint/Doc/tutorial/datastructures.rst
==============================================================================
--- python/branches/release27-maint/Doc/tutorial/datastructures.rst	(original)
+++ python/branches/release27-maint/Doc/tutorial/datastructures.rst	Fri Oct 15 17:31:09 2010
@@ -481,8 +481,8 @@
 
 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::
 


More information about the Python-checkins mailing list