How do I initialize a list please?

Dan Bishop danb_83 at yahoo.com
Tue Dec 31 16:15:54 EST 2002


Gerhard Häring <gerhard.haering at gmx.de> wrote in message news:<mailman.1041347835.14601.python-list at python.org>...
> * OUTLand <cmfinlay at SPAMmagnet.com.au> [2003-01-01 02:07 +1100]:
> > How do I initialize a list please?
[snip]
> dim = [1.0] * 10
> 
> But don't do this for two-dimensional arrays:
> 
> dim = [[1.0] * 10] * 10
> 
> as this will give you a list with ten references to the *same* inner
> list.

But this will work:

# code from a program I wrote recently
self.__data = [[0] * numColumns for i in xrange(numRows)]



More information about the Python-list mailing list