I intend to initialize a list of list with length of n.
x = [[]] * n
However, this somehow links the lists together.
>>> x = [[]] * 3
>>> x[1].append(0)
>>> x
[[0], [0], [0]]
I expect to have something like:
[[], [0], []]
Any ideas?
I intend to initialize a list of list with length of n.
x = [[]] * n
However, this somehow links the lists together.
>>> x = [[]] * 3
>>> x[1].append(0)
>>> x
[[0], [0], [0]]
I expect to have something like:
[[], [0], []]
Any ideas?