[Tutor] filling 2d array with zeros

Alex Hall mehgcap at gmail.com
Mon Sep 27 19:54:55 CEST 2010


Hi again everyone,
I have a 2d array (I guess it is technically a list) which I want to
fill with zeros. Later I will change some values, but any I do not
change have to be zeros. I have two complex for loops, but I tried to
scale things down to a couple list comprehensions and I broke things.
What is wrong with the following line?
self.am=[[(a,b) for a in range(len(self.lines)) a=0] for b in
range(len(self.lines)) b=0]

self.lines is another array that tells self.am how big to get, but no
matter the size, all created cells of the self.am 2d array should end
up with a value of 0. I barely understand list comprehensions as it is
so am not sure what I did wrong here. I adapted this from a working
example that fills a 2d array with numbers.

-- 
Have a great day,
Alex (msg sent from GMail website)
mehgcap at gmail.com; http://www.facebook.com/mehgcap


More information about the Tutor mailing list