List behaviour

barberomarcelo at gmail.com barberomarcelo at gmail.com
Wed May 17 11:06:54 EDT 2006


Maybe I'm missing something but the latter is not the behaviour I'm
expecting:

>>> a = [[1,2,3,4], [5,6,7,8]]
>>> b = a[:]
>>> b
[[1, 2, 3, 4], [5, 6, 7, 8]]
>>> a == b
True
>>> a is b
False
>>> for i in range(len(b)):
...     for x in range(4):
...         b[i][x] = b[i][x] + 10
...
>>> b
[[11, 12, 13, 14], [15, 16, 17, 18]]
>>> a
[[11, 12, 13, 14], [15, 16, 17, 18]]
>>>



ActivePython 2.4.2 Build 248 (ActiveState Corp.) based on
Python 2.4.2 (#67, Oct 30 2005, 16:11:18) [MSC v.1310 32 bit (Intel)]
on win32
Windows XP

Marcelo




More information about the Python-list mailing list