[ [ [] * y for y in range(3) ] * x for x in range(2) ]
Isaac To
kkto at csis.hku.hk
Thu Jan 30 00:00:19 EST 2003
>>>>> "Marcel" == Marcel <marcel_achim at videotron.ca> writes:
Marcel> Hi, I'm trying to allocate nested lists up-front using the
Marcel> subject line, instead of generating : [ [ [], [], [] ], [ [],
Marcel> [], [] ] ] I end up with : [ [], [ [], [], [] ] ]
Marcel> I guess I screwed up something, but I'm failing to understand
Marcel> what...
Marcel> Any idea ?
Hint: range(3) means [0,1,2], so [[]*y for y in [0,1,2]] has first element
[], second [[]], third [[], []].
Regards,
Isaac.
More information about the Python-list
mailing list