Could someone explain this multidimensional list behaviour?

Kragen Sitaker kragen at canonical.org
Sat Nov 24 01:46:48 EST 2001


Aaron Sterling <dhaaron at hotpop.com> writes:

> The second for loop should not be necessary. something like:
> 
> spam = []
> for y in range(n):
>     spam.append([0] * n)

You can also write that with map() as map(lambda y: [0] * n, range(n))
or with a list comprehension as [[0] * n for y in range(n)].  Hope
this helps.




More information about the Python-list mailing list