initialized list: strange behavior

alexander.genkin at gmail.com alexander.genkin at gmail.com
Tue Nov 25 07:34:24 CET 2008


Hi Python experts! Please explain this behavior:

>>> nn=3*[[]]
>>> nn
[[], [], []]
>>> mm=[[],[],[]]
>>> mm
[[], [], []]

Up till now, 'mm' and 'nn' look the same, right? Nope!

>>> mm[1].append(17)
>>> mm
[[], [17], []]
>>> nn[1].append(17)
>>> nn
[[17], [17], [17]]

???

Python 2.5 Win XP

Thanks!



More information about the Python-list mailing list