This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Dictionary created with dict.fromkeys have issues (all explained in the file)
Type: behavior Stage: resolved
Components: ctypes Versions: Python 3.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Jim Fasarakis-Hilliard, christian.heimes, hung son luong
Priority: normal Keywords:

Created on 2020-06-03 08:14 by hung son luong, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue_of_python_dict.py hung son luong, 2020-06-03 08:14 the python file demonstrated the issues of dict.fromkeys when pop and add new items
Messages (2)
msg370644 - (view) Author: Jim Fasarakis-Hilliard (Jim Fasarakis-Hilliard) * Date: 2020-06-03 08:35
This isn't an issue, `value` (that is, `{}` here) is shared among all keys. Since you've added a mutable value, when you mutate it this change is seen for all keys holding the value. 

This is documented in dict.fromkeys https://docs.python.org/3/library/stdtypes.html#dict.fromkeys
msg370646 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2020-06-03 08:39
Yes, this is intended behavior.

Thanks Jim!
History
Date User Action Args
2022-04-11 14:59:31adminsetgithub: 85029
2020-06-03 08:39:26christian.heimessetstatus: open -> closed

nosy: + christian.heimes
messages: + msg370646

resolution: not a bug
stage: resolved
2020-06-03 08:35:13Jim Fasarakis-Hilliardsetnosy: + Jim Fasarakis-Hilliard
messages: + msg370644
2020-06-03 08:14:48hung son luongcreate