Could someone explain this multidimensional list behaviour?

Kragen Sitaker kragen at
Sat Nov 24 07:46:48 CET 2001

Aaron Sterling <dhaaron at> 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