# Nested list comprehensions act like real for loops:
>>> a = [[None for i in range(3)] for j in range(3)]
>>> a
[[None, None, None], [None, None, None], [None, None, None]]
>>> a[0][0] = 5
>>> a
[[5, None, None], [None, None, None], [None, None, None]]
# Side-effect: i and j will be changed.

# Another way (much less clear to my eyes):
>>> a = map(lambda x: map(lambda x: None, range(3)), range(3))
>>> a[0][0]=5
>>> a
[[5, None, None], [None, None, None], [None, None, None]]

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to