Re: Initializing a list of lists

2006-03-19 Thread Ron Adam
[EMAIL PROTECTED] wrote: > I want to create a list of lists, each of which is identical, but which > can be modified independently i.e: > x = [ [0], [0], [0] ] x[0].append(1) x > [[0, 1], [0], [0]] > > The above construct works if I have only few items, but if I have many, > I'd pr

Re: Initializing a list of lists

2006-03-19 Thread ZeD
Ciao, [EMAIL PROTECTED] Che stavi dicendo? > Is there a simple way to create a list of independent lists? N=3 x=[[0] for e in range(N)] -- Up da 1 giorno, 3 ore, 43 minuti e 10 secondi -- http://mail.python.org/mailman/listinfo/python-list

Re: Initializing a list of lists

2006-03-19 Thread Tim Chase
> The above construct works if I have only few items, but if I have many, > I'd prefer to write > N =3 x =N*[[0]] x > > [[0], [0], [0]] > > If I now try extending the lists indepently, I cannot, as they all > point to the same list object > x[0].append(1) x > > [[0, 1], [0,

Initializing a list of lists

2006-03-19 Thread tkpmep
I want to create a list of lists, each of which is identical, but which can be modified independently i.e: >>>x = [ [0], [0], [0] ] >>> x[0].append(1) >>> x [[0, 1], [0], [0]] The above construct works if I have only few items, but if I have many, I'd prefer to write >>> N =3 >>> x =N*[[0]] >>> x