Arrays?
Jeff Epler
jepler at unpythonic.net
Wed Nov 13 15:32:26 EST 2002
On Wed, Nov 13, 2002 at 07:54:53PM +0000, Wojtek Walczak wrote:
> Dnia Wed, 13 Nov 2002 19:15:28 -0000, e-tones.co.uk napisa?(a):
> > So im looking to creat a list? If so, how do I make it 2 dimensional?
>
> >>> a=[[]]*2
> >>> a
> [[], []]
> >>>
>
> Is that what you wanted?
Almost certainly not.
>>> a = [[]]*2
>>> a
[[], []]
>>> a[0].append(1)
>>> a
[[1], [1]]
oops!
You might want
>>> a = [ [] for i in range(2) ]
instead
>>> a = [ [] for i in range(2) ]
>>> a
[[], []]
>>> a[0].append(1)
>>> a
[[1], []]
Jeff
More information about the Python-list
mailing list