Re: First post from a Python newbiw

2008-03-03 Thread Christoph Zwerschke
Arnaud Delobelle schrieb: > It's a FAQ: > http://www.python.org/doc/faq/programming/#how-do-i-create-a-multidimensional-list Somewhere on my todo list I have "read through the whole Python FAQ", but so far never got round doing it. Should probably set it to prio A. -- Christoph -- http://mail.p

Re: First post from a Python newbiw

2008-03-03 Thread Arnaud Delobelle
Steve Turner wrote: > I finally decided to have a go with Python and am working through the > tutorial. Great! > On my old BBC Computer [...] These were nice machines... > In Python I thought I could do this with: > > >>> a=[0,0,0] > >>> b=[a,a,a] > >>> b > [[0, 0, 0], [0, 0, 0], [0, 0, 0]] >

Re: First post from a Python newbiw

2008-03-02 Thread Jeff Schwab
[EMAIL PROTECTED] wrote: > 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. > > ... whereas you reassign all three elem

Re: First post from a Python newbiw

2008-03-02 Thread castironpi
> >>> 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. ... whereas you reassign all three elements of [0]* 3. >>> ((0,)

Re: First post from a Python newbiw

2008-03-02 Thread Jeff Schwab
Christoph Zwerschke wrote: > Marc 'BlackJack' Rintsch schrieb: >> On Sun, 02 Mar 2008 14:15:09 +, 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 xran

Re: First post from a Python newbiw

2008-03-02 Thread Terry Reedy
"Christoph Zwerschke" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | Marc 'BlackJack' Rintsch schrieb: | > On Sun, 02 Mar 2008 14:15:09 +, 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

Re: First post from a Python newbiw

2008-03-02 Thread Marc 'BlackJack' Rintsch
On Sun, 02 Mar 2008 21:58:31 +0100, Christoph Zwerschke wrote: > Marc 'BlackJack' Rintsch schrieb: >> On Sun, 02 Mar 2008 14:15:09 +, 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?

Re: First post from a Python newbiw

2008-03-02 Thread Steve Turner
Christoph Zwerschke wrote: : Marc 'BlackJack' Rintsch schrieb: :: On Sun, 02 Mar 2008 14:15:09 +, 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

Re: First post from a Python newbiw

2008-03-02 Thread Christoph Zwerschke
Marc 'BlackJack' Rintsch schrieb: > On Sun, 02 Mar 2008 14:15:09 +, 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 ? --

Re: First post from a Python newbiw

2008-03-02 Thread Steve Turner
Marc 'BlackJack' Rintsch wrote: : On Sun, 02 Mar 2008 14:15:09 +, 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)] Thanks, Marc. -- Steve --

Re: First post from a Python newbiw

2008-03-02 Thread Marc 'BlackJack' Rintsch
On Sun, 02 Mar 2008 14:15:09 +, 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)] Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/list

First post from a Python newbiw

2008-03-02 Thread Steve Turner
I finally decided to have a go with Python and am working through the tutorial. On my old BBC Computer I could do something like this: DIM A(2,2) to create a 3 by 3 array of data. Then I could set any point: A(0,0) = foo A(0,1) = bar etc. In Python I thought I could do this with: >>> a=[0,0,