Take the following 2 cases:
>>> a, b = [[None, None]]*2
>>> print(a, b)
[None, None] [None, None]
>>> a[0] = 1
>>> print(a, b)
[1, None] [1, None]
&
>>> a, b = [[None, None], [None, None]]
>>> print(a, b)
[None, None] [None, None]
>>> a[0] = 1
>>> print(a, b)
[1, None] [None, None]
- I don't understand why the first case does not exhibit the same behavior as the second case since
[[None, None]]*2 == [[None, None],[None, None]]
returnsTrue
.
I suspect it's because when the list is multiplied, the new components will point to the values from the first components. How sane is this?
- How can I make the first case behave just like the second one?