List Init Behavior
Remco Gerlich
scarblac-spamtrap at pino.selwerd.nl
Wed Mar 8 07:49:24 EST 2000
Gene Chiaramonte wrote in comp.lang.python:
> What I really want to do is quickly init a large list of lists where each
> row is its own list. Not all rows pointing to the same list as above. Any
> ideas?
>
> This works - but I like the one line syntax better.
> x = 5
> y = 10
> l = [0]*y
> for i in range(y):
> l[i] = [0]*x
This is a FAQ. The FAQ gives exactly that answer. It also adds
"If you feel weird, you can also do it in the following way.
w, h = 2, 3
A = map(lambda i,w=w: [None] * w, range(h))
"
--
Remco Gerlich, scarblac at pino.selwerd.nl
This space intentionally left blank.
More information about the Python-list
mailing list