L1 is a list of three different lists, although each list holds the
same values.

L2 is a list of three references to the same list (the '*' operator
doesn't do a deep copy).  So when you modify any of the referenced
lists, you modify all of them.

Try this:

>>> q = [1, 1, 1]
>>> r = [q, q, q]
>>> r
[[1, 1, 1], [1, 1, 1], [1, 1, 1]]
>>> r[0][0] = 999
>>> r
[[999, 1, 1], [999, 1, 1], [999, 1, 1]]

Regards, Casey
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to