Zachary Ware <zachary.w...@gmail.com> added the comment:

See 
https://docs.python.org/3/faq/programming.html#how-do-i-create-a-multidimensional-list

Not quite the same example, but the underlying reason for what you're seeing is 
the same: each of the `dict` objects in `[{}] * 4` is actually the *same* dict 
object:

>>> inner = {}
>>> details = [inner] * 4
>>> details
[{}, {}, {}, {}]
>>> assert all(d is inner for d in details)
>>> # Instead, do:
>>> details = [{} for each in range(4)]
>>> details
[{}, {}, {}, {}]
>>> details[1]['A'] = 5
>>> details
[{}, {'A': 5}, {}, {}]

----------
nosy: +zach.ware
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue45437>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to