idiom for initial list of lists

Tim Peters tim_one at email.msn.com
Fri Sep 8 13:05:03 EDT 2000


[Robin Becker]
> ...
> so I'm forced to use the rather pedantic
> S=[]
> for i in range(n): S[i].append([])

That doesn't make sense.  Get rid of the "[i]" and it does, though.

Note that in 2.0b1 it can be a listcomp one-liner:

    S = [[] for i in range(n)]

which, once you're accustomed to reading listcomps, very clearly says "OK,
it's a list of empty lists ... and there are n of them".






More information about the Python-list mailing list