Initilizing MD lists w/ objects.
Gerhard Häring
gerhard at bigfoot.de
Fri Apr 12 23:27:07 EDT 2002
Philip Swartzleonard wrote in comp.lang.python:
> I'm looking for a reasonable way to initilize a multidimensional list with
> a bunch of blank objects of some type (already been burned by using [obj
> ()] * 400 or similar =). This is the best i've come up with, but it seems
> icky:
>
> self.data = [None]*40
>
> for x in range(40):
> self.data[x] = []
> for y in range(40):
> self.data[x].append(Vis_cell())
What about list comprehensions, like:
self.data = [[Vis_cell() for column in range(40)] for row in range(40)]
Gerhard
--
mail: gerhard <at> bigfoot <dot> de registered Linux user #64239
web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930
public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930
reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b')))
More information about the Python-list
mailing list