First post from a Python newbiw
Marc 'BlackJack' Rintsch
bj_666 at gmx.net
Sun Mar 2 16:48:52 EST 2008
On Sun, 02 Mar 2008 21:58:31 +0100, 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)]
>
> Why not simply [[0]*3]*3 ?
Because:
In [77]: a = [[0] * 3] * 3
In [78]: a
Out[78]: [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
In [79]: a[0][0] = 42
In [80]: a
Out[80]: [[42, 0, 0], [42, 0, 0], [42, 0, 0]]
Ciao,
Marc 'BlackJack' Rintsch
More information about the Python-list
mailing list