diff options
Diffstat (limited to 'Doc/tutorial/controlflow.rst')
-rw-r--r-- | Doc/tutorial/controlflow.rst | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/Doc/tutorial/controlflow.rst b/Doc/tutorial/controlflow.rst index a9247cd0b9..5c7ca4e0a4 100644 --- a/Doc/tutorial/controlflow.rst +++ b/Doc/tutorial/controlflow.rst @@ -429,11 +429,12 @@ function like this:: def cheeseshop(kind, *arguments, **keywords): print "-- Do you have any", 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 - 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:: @@ -454,10 +455,9 @@ and of course it would print:: shopkeeper : Michael Palin sketch : Cheese Shop Sketch -Note that the :meth:`sort` method of the list of keyword argument names is -called before printing the contents of the ``keywords`` dictionary; if this is -not done, the order in which the arguments are printed is undefined. - +Note that the list of keyword argument names is created by sorting the result +of the keywords dictionary's ``keys()`` method before printing its contents; +if this is not done, the order in which the arguments are printed is undefined. .. _tut-arbitraryargs: |