#8267: Use sorted() to get a sorted list of dict keys.
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 @@
        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::