0

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]
  1. 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]] returns True.

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?

  1. How can I make the first case behave just like the second one?
Sandu Ursu
  • 1,181
  • 1
  • 18
  • 28

0 Answers0