A simple question
skip at pobox.com
skip at pobox.com
Sat Mar 4 23:20:49 EST 2006
>>> x=[[0]*2]*2
This replicates the references. It doesn't copy objects.
This short transcript demonstrates that concept:
>>> x = [[0, 0], [0, 0]]
>>> map(id, x)
[16988720, 16988160]
>>> y = [[0]*2]*2
>>> y
[[0, 0], [0, 0]]
>>> map(id, y)
[16988520, 16988520]
The object x refers to is a list with references to two other lists. The
object y refers to is a list with two references to the same list.
Skip
More information about the Python-list
mailing list