initialising a list of lists
p.c.j.kleiweg at rug.nl
Wed Nov 16 13:58:45 CET 2005
This does not what I want it to do:
>>> a = [] * 6
[['X'], ['X'], ['X'], ['X'], ['X'], ['X']]
This does what I want:
>>> b = [ for _ in range(6)]
[, , , ['X'], , ]
The first is clear and wrong. The second is hairy and right.
Is there a way to do it clear and right?
Peter Kleiweg L:NL,af,da,de,en,ia,nds,no,sv,(fr,it) S:NL,de,en,(da,ia)
More information about the Python-list