]> granicus.if.org Git - python/commitdiff
Revise cheeseshop example so that the order of the keyword output is
authorFred Drake <fdrake@acm.org>
Tue, 29 Jan 2002 14:53:30 +0000 (14:53 +0000)
committerFred Drake <fdrake@acm.org>
Tue, 29 Jan 2002 14:53:30 +0000 (14:53 +0000)
completely determined by the example; dict insertion order and the string
hash algorithm no longer affect the output.
This fixes SF bug #509281.

Doc/tut/tut.tex

index 608388bc3ea066a7bb3080d6a7139f9bef6fb948..27f33c984fe081670f6eb8f9e6dd243f47002802 100644 (file)
@@ -1485,7 +1485,9 @@ def cheeseshop(kind, *arguments, **keywords):
     print "-- I'm sorry, we're all out of", kind
     for arg in arguments: print arg
     print '-'*40
-    for kw in keywords.keys(): print kw, ':', keywords[kw]
+    keys = keywords.keys()
+    keys.sort()
+    for kw in keys: print kw, ':', keywords[kw]
 \end{verbatim}
 
 It could be called like this:
@@ -1511,6 +1513,11 @@ shopkeeper : Michael Palin
 sketch : Cheese Shop Sketch
 \end{verbatim}
 
+Note that the \method{sort()} method of the list of keyword argument
+names is called before printing the contents of the \code{keywords}
+dictionary; if this is not done, the order in which the arguments are
+printed is undefined.
+
 
 \subsection{Arbitrary Argument Lists \label{arbitraryArgs}}