-2
list = [[0,0]]
x = [0,0]
for i in range(5):
  x[0] += 1
  list.append(x)

expected result: [[1,0],[2,0],[3,0],[4,0],[5,0]] actual result: [[5,0],[5,0],[5,0],[5,0],[5,0]]

I have tried several things, but none seem to work.

I am open to any suggestions, I am trying to keep "x" as a list and would prefer to stay away from doing something like

x1 = x[0]
x2 = x[1]

1 Answers1

0

I think the problem is that it’s appending the list, not its contents, so it changes each time to the current value of the list(x). However, I’m really not sure what the exact problem is.

You could solve your problem by doing the following:

List=[[0,0]]
x=0
for I in range(5):
    x += 1
    list.append([x,0])
Alex Waygood
  • 6,304
  • 3
  • 24
  • 46
codelife
  • 11
  • 2