I want to append a list into another list using nested for loops but the code is not working as expected
def apend():
ls = []
numbers = [0,0]
for num1 in range(3):
for num2 in range(2):
numbers[0] = num1
numbers[1] = num2
ls.append(numbers)
print(ls)
apend()
I expect the output to be: [[0,0],[0,1],[0,2],1,0],[1,1],[1,2]]
but i get this output: [[1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2]]

numbersin your inner for loop.[num1, num2]instead.lskeeps it as reference to the samenumbersbut you should create newnumberbefore you put it inls. OR dols.append([num1, num2])BTW: run your code on pythontutor.com and you will see references as arrows on visualization - and all arrows with refere to the same listnumber