0

Why couldn't the first element but the whole column be updated below?

>>> x=2*[2*[1]]
>>> x
[[1, 1], [1, 1]]
>>> x[0][0]=2
>>> x
[[2, 1], [2, 1]]
U13-Forward
  • 69,221
  • 14
  • 89
  • 114
sof
  • 9,113
  • 16
  • 57
  • 83

1 Answers1

0

Even tho this is a clear duplicate but use range:

>>> x=[[1 for i in range(2)] for x in range(2)]
>>> x
[[1, 1], [1, 1]]
>>> x[0][0]=2
>>> x
[[2, 1], [1, 1]]
>>> 

At least still able to do:

>>> x=[[1]*2 for x in range(2)]
>>> x[0][0]=2
>>> x
[[2, 1], [1, 1]]
>>> 
U13-Forward
  • 69,221
  • 14
  • 89
  • 114