0

I'm working on a nested for loop now, but something just goes wrong. As below:

result = [[None] * 5] *2

l = range(10) 

for i in range(2):
    for j in range(i*5, (i+1)*5):
        result[i][j%5] = l[j]

print(result)

But the returned result is not as expected

[[0,1,2,3,4],[5,6,7,8,9]]

Instead I got a result of

[[5,6,7,8,9],[5,6,7,8,9]]

What seems to be the problem?

Yujian
  • 169
  • 1
  • 10

0 Answers0