I have one list of sublists from which I am deriving another list of sublist by appending repeated sublist. Now when I am trying to replace None
with incremental value, I notice that appended sublist is also changing. Can someone help me understand what am I doing wrong here?
b = [[1,None,3],[4,5,1],[7,None,2]]
a = []
for i in b:
for rp in range(i[2]):
a.append(i)
print(b)
print(a)
c = 0
for i in range(len(a)):
if a[i][1]==None:
a[i][1] = c
c = c + 1
print(a)
Output:
[[1, None, 3], [4, 5, 1], [7, None, 2]]
[[1, None, 3], [1, None, 3], [1, None, 3], [4, 5, 1], [7, None, 2], [7, None, 2]]
[[1, 0, 3], [1, 0, 3], [1, 0, 3], [4, 5, 1], [7, 1, 2], [7, 1, 2]]
Expected output:
[[1, 0, 3], [1, 1, 3], [1, 2, 3], [4, 5, 1], [7, 3, 2], [7, 4, 2]]