Rotwang <sg...@hotmail.co.uk> wrote:
> Can anybody tell me what's going on?

Your problem is basically this:

>>> a = [1]
>>> b = [a] * 2
>>> b
[[1], [1]]
>>> a.append(2)
>>> b
[[1, 2], [1, 2]]

The expression '[a] * 2' doesn't make two copies of list of a list of
a, it makes two nested _references_ to it. When you modify the 'first'
list, you're seeing that changed reflected in the second reference.

The list comprehension, however, is returning a _new_ list each time.
Changing its contents doesn't affect any of the other independently
created lists.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to