List behaviour

Gabriel gabe at dragffy.com
Thu May 15 06:08:11 EDT 2008


Hi all

Just wondering if someone could clarify this behaviour for me, please?

>>> tasks = [[]]*6
>>> tasks
[[], [], [], [], [], []]
>>> tasks[0].append(1)
>>> tasks
[[1], [1], [1], [1], [1], [1]]

Well what I was expecting to end up with was something like:
>>> tasks
[[1], [], [], [], [], []]


I got this example from page 38 of Beginning Python.

Regards

Gabriel






More information about the Python-list mailing list