[issue9108] list object variable assign with multiplication sign
Ezio Melotti
report at bugs.python.org
Mon Jun 28 23:40:12 CEST 2010
Ezio Melotti <ezio.melotti at gmail.com> added the comment:
That's because with [{}] * 3 you get a list with 3 copies of the same object, so all the elements in c refer to the same dict:
>>> a = [{}, {}, {}]
>>> b = [{}] + [{}] + [{}]
>>> c = [{}] * 3
>>> map(id, a)
[12850496, 12850784, 12850928]
>>> map(id, b)
[12851648, 12851072, 12851792]
>>> map(id, c)
[12852080, 12852080, 12852080]
----------
nosy: +ezio.melotti
resolution: -> invalid
stage: -> committed/rejected
status: open -> closed
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9108>
_______________________________________
More information about the Python-bugs-list
mailing list