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?

1 Answer
1

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *