Skip to content

Commit 5e5bbbe

Browse files
Stigjbmethane
authored andcommitted
bpo-34083: Update dict order in Functional HOWTO (GH-8230)
1 parent 33aefad commit 5e5bbbe

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

Doc/howto/functional.rst

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -273,23 +273,24 @@ dictionary's keys::
273273

274274
>>> m = {'Jan': 1, 'Feb': 2, 'Mar': 3, 'Apr': 4, 'May': 5, 'Jun': 6,
275275
... 'Jul': 7, 'Aug': 8, 'Sep': 9, 'Oct': 10, 'Nov': 11, 'Dec': 12}
276-
>>> for key in m: #doctest: +SKIP
276+
>>> for key in m:
277277
... print(key, m[key])
278-
Mar 3
278+
Jan 1
279279
Feb 2
280-
Aug 8
281-
Sep 9
280+
Mar 3
282281
Apr 4
282+
May 5
283283
Jun 6
284284
Jul 7
285-
Jan 1
286-
May 5
285+
Aug 8
286+
Sep 9
287+
Oct 10
287288
Nov 11
288289
Dec 12
289-
Oct 10
290290

291-
Note that the order is essentially random, because it's based on the hash
292-
ordering of the objects in the dictionary.
291+
Note that starting with Python 3.7, dictionary iteration order is guaranteed
292+
to be the same as the insertion order. In earlier versions, the behaviour was
293+
unspecified and could vary between implementations.
293294

294295
Applying :func:`iter` to a dictionary always loops over the keys, but
295296
dictionaries have methods that return other iterators. If you want to iterate
@@ -301,8 +302,8 @@ The :func:`dict` constructor can accept an iterator that returns a finite stream
301302
of ``(key, value)`` tuples:
302303

303304
>>> L = [('Italy', 'Rome'), ('France', 'Paris'), ('US', 'Washington DC')]
304-
>>> dict(iter(L)) #doctest: +SKIP
305-
{'Italy': 'Rome', 'US': 'Washington DC', 'France': 'Paris'}
305+
>>> dict(iter(L))
306+
{'Italy': 'Rome', 'France': 'Paris', 'US': 'Washington DC'}
306307

307308
Files also support iteration by calling the :meth:`~io.TextIOBase.readline`
308309
method until there are no more lines in the file. This means you can read each

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy