First post from a Python newbiw

Jeff Schwab jeff at schwabcenter.com
Sun Mar 2 17:11:24 EST 2008


Christoph Zwerschke wrote:
> Marc 'BlackJack' Rintsch schrieb:
>> On Sun, 02 Mar 2008 14:15:09 +0000, Steve Turner wrote:
>>
>>> Apart from doing something like
>>> a=[0,0,0]
>>> b=[0,0,0]
>>> c=[0,0,0]
>>> d=[a,b,c]
>>>
>>> is there a better way of creating d??
>>
>> a = [[0] * 3 for dummy in xrange(3)]

Each element of a refers to a distinct array.

> Why not simply [[0]*3]*3 ?

All three elements of the result refer to the same array.



More information about the Python-list mailing list