[issue27668] list illogical affectation

Emanuel Barry report at bugs.python.org
Tue Aug 2 08:21:28 EDT 2016


Emanuel Barry added the comment:

To add to what SilentGhost just said; the '*' operator for lists doesn't create new lists, but simply creates new references to the same list (i.e. it doesn't re-evaluate the expression).

To create separate lists, you can do a list comprehension such as:

[['x'] * 3 for _ in range(3)]

More information is available on the FAQ: https://docs.python.org/3/faq/programming.html#why-did-changing-list-y-also-change-list-x

----------
assignee: terry.reedy -> 
nosy: +ebarry

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue27668>
_______________________________________


More information about the Python-bugs-list mailing list