I'm trying to initialize an empty list as [[], []] and then append to it. However, I am getting unexpected results with the following method vs another. What is going on under the hood in this scenario?
y = [[]] * 2
print(y)
y[0].append(1)
y[1].append(2)
print(y)
output:
[[],[]]
[[1,2], [1,2]]
While this following code gives me the intended results that I want.
x = [[], []]
print(x)
x[0].append(1)
x[1].append(2)
print(x)
output:
[[],[]]
[[1], [2]]