Hello.
In Python, in a loop of lists, a = [-1] `` `does not rewrite the original list, but
a [0] = -1``` Rewrite.
alist = [[0], [0], [0]]
for a in alist:
a = [-1]
print(alist) # ==> [[0], [0], [0]]
for a in alist:
a[0] = -1
print(alist) # ==> [[-1], [-1], [-1]]
$ python3 -V
Python 3.7.7
Recommended Posts