idiom for initial list of lists
Pekka Pessi
Pekka.Pessi at nokia.com
Sun Sep 10 15:31:51 EDT 2000
In message <Pine.LNX.4.21.0009081645290.1107-100000 at fep132.fep.ru> Oleg Broytmann <phd at phd.russ.ru> writes:
>> so I'm forced to use the rather pedantic
>> S=[]
>> for i in range(n): S[i].append([])
> That's the only and one correct way.
I prefer list():
>>> a = map(list, 5 * [[]])
>>> a[0].append(1)
>>> a
[[1], [], [], [], []]
or
>>> a = map(list, 5 * ((),))
>>> a
[[], [], [], [], []]
>>> a[0].append(1)
>>> a
[[1], [], [], [], []]
Pekka
More information about the Python-list
mailing list