0
list.append(x)

Add an item to the end of the list.

Okay. Let's write some code:

x = [[]]*3
x[0].append('foo')
print x

and output is:

[['foo'], ['foo'], ['foo']]

Why?

1 Answers1

1

x = [[]]*3 Creates a list of length 3 where each element have the same reference. So appending to any element will give this result.

M4rtini
  • 13,186
  • 4
  • 35
  • 42