So, I was returning to python from C and had forgotten how to make 2D Arrays in python. So, I came up with this quick and dirty trick of appending a list over and over again into an empty list with a for loop. However, when I try to update a single element, the entire column gets updated
l=[]
pp=[]
for i in range(5):
pp.append(0)
for i in range(5):
l.append(pp)
l[0][2]=5
for i in l:
print(i)
The output I expect:
[0, 0, 5, 0, 0]
[0, 0, 0, 0, 0]
[0, 0, 0, 0, 0]
[0, 0, 0, 0, 0]
[0, 0, 0, 0, 0]
The output I get:
[0, 0, 5, 0, 0]
[0, 0, 5, 0, 0]
[0, 0, 5, 0, 0]
[0, 0, 5, 0, 0]
[0, 0, 5, 0, 0]