[issue45908] dict.fromkeys insertion order

Vedran Čačić report at bugs.python.org
Sat Nov 27 03:02:49 EST 2021


New submission from Vedran Čačić <vedgar at gmail.com>:

I'm sure this is exactly how it should work, I just want to know if you think it is documented properly, so I can rely on it. In my opinion the docs should be more precise.

>>> ''.join(dict.fromkeys('axbxc'))
'axbc'

Is this guaranteed by the documentation? Of course, dict iteration order is now guaranteed to be insertion order, but still, nowhere do the docs say that fromkeys inserts the keys into new dictionary in order in which they appear in its argument.

(Probably the reason for this is that dict iteration order was fixed in 3.7, yet fromkeys existed a long time before that.)

I propose an addition to the documentation:

> Create a new dictionary with keys from iterable (in order) and values set to value.

https://docs.python.org/3/library/stdtypes.html

----------
assignee: docs at python
components: Documentation
messages: 407136
nosy: docs at python, veky
priority: normal
severity: normal
status: open
title: dict.fromkeys insertion order
versions: Python 3.10, Python 3.11

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45908>
_______________________________________


More information about the Python-bugs-list mailing list