I have this two sets of code, i assume both should have equal output but they dont. Can someone tell what is going through both code? Any insight is much appreciated. Set 1
x = [[1],[1],[1],[1],[1]]
for i in x:
print(i)
x[1][0]=99
print(x[1][0])
for i in x:
print(i)
The output for set1 is
[1]
[1]
[1]
[1]
[1]
99
[1]
[99]
[1]
[1]
[1]
Set2
y = [1]
x = []
for i in range(5):
x.append(y)
for i in x:
print(i)
x[1][0]=99
print(x[1][0])
for i in x:
print(i)
The output for set2 is
[1]
[1]
[1]
[1]
[1]
99
[99]
[99]
[99]
[99]
[99]