From 2b7cd229c85c656c4cd2e973325167d8e2fceedd Mon Sep 17 00:00:00 2001 From: DimitrisJim Date: Thu, 16 Feb 2017 22:11:24 +0200 Subject: [PATCH 1/2] bpo-29453: Remove reference to undefined dictionary ordering in Tutorial As of Python 3.6 **kwargs are ordered, thus, remove the paragraph stating that ordering is undefined and change snippet to remove the unecessary sorted call. --- Doc/tutorial/controlflow.rst | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Doc/tutorial/controlflow.rst b/Doc/tutorial/controlflow.rst index d43461886e7933..3cf402ce2d90a0 100644 --- a/Doc/tutorial/controlflow.rst +++ b/Doc/tutorial/controlflow.rst @@ -492,8 +492,7 @@ function like this:: for arg in arguments: print(arg) print("-" * 40) - keys = sorted(keywords.keys()) - for kw in keys: + for kw in keywords: print(kw, ":", keywords[kw]) It could be called like this:: @@ -513,13 +512,10 @@ and of course it would print: It's very runny, sir. It's really very, VERY runny, sir. ---------------------------------------- - client : John Cleese shopkeeper : Michael Palin + client : John Cleese sketch : Cheese Shop Sketch -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: From b565db51839342e0f9d0e556edff0c20db8af043 Mon Sep 17 00:00:00 2001 From: DimitrisJim Date: Sat, 18 Feb 2017 16:32:09 +0200 Subject: [PATCH 2/2] Add sentence mentioning guaranteed output order of kwargs --- Doc/tutorial/controlflow.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Doc/tutorial/controlflow.rst b/Doc/tutorial/controlflow.rst index 3cf402ce2d90a0..6a9bb4889ff857 100644 --- a/Doc/tutorial/controlflow.rst +++ b/Doc/tutorial/controlflow.rst @@ -516,6 +516,9 @@ and of course it would print: client : John Cleese sketch : Cheese Shop Sketch +Note that the order in which the keyword arguments are printed is guaranteed +to match the order in which they were provided in the function call. + .. _tut-arbitraryargs: