Initilizing MD lists w/ objects.
Philip Swartzleonard
starx at pacbell.net
Sat Apr 13 00:16:23 EDT 2002
Gerhard =?iso-8859-15?Q?H=E4ring?= || Fri 12 Apr 2002 08:27:07p:
> 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)]
Oh. That's perfect. Thanks =).
(Just having also just found out that
for x in data: for cell in x: cell.wahatever
works as well as a double for in range =)
--
Philip Sw "Starweaver" [rasx] :: www.rubydragon.com
More information about the Python-list
mailing list