example code:
my_list = [[]] * 4
my_list[2].append(3)
print my_list
expected: [[], [], [3], []]
actual: [[3], [3], [3], [3]]
My inference is that the nested lists are copies of one another. Is there a way to achieve the expected
?
Assign 3
a different way
l = [[]] * 4
l[2] = [3]
print(l)
(xenial)vash@localhost:~/python/stack_overflow$ python3.7 rows.py [[], [], [3], []]