[issue38934] Dictionaries of dictionaries behave incorrectly when created from dict.fromkeys()

Josh Rosenberg report at bugs.python.org
Wed Nov 27 23:02:48 EST 2019


Josh Rosenberg <shadowranger+python at gmail.com> added the comment:

That's the expected behavior, and it's clearly documented here: https://docs.python.org/3/library/stdtypes.html#dict.fromkeys

Quote: "All of the values refer to just a single instance, so it generally doesn’t make sense for value to be a mutable object such as an empty list. To get distinct values, use a dict comprehension instead."

----------
nosy: +josh.r
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

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


More information about the Python-bugs-list mailing list