Emanuel Barry added the comment:

Another way to fix this would be the following:

>>> l=[[''] * 2 for _ in range(3)]
>>> l
[['', ''], ['', ''], ['', '']]
>>> l[0][1] = "A"
>>> l
[['', 'A'], ['', ''], ['', '']]

The * operator on lists doesn't create new elements, it only adds new 
references to them. A list comprehension will evaluate the expression each 
time, while repetition (the * operator) will only evaluate it once.

----------

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

Reply via email to