any better code to initalize a list of lists?
Paul Rubin
http
Thu Mar 8 20:27:01 EST 2007
"John" <rds1226 at sh163.net> writes:
> For my code of radix sort, I need to initialize 256 buckets. My code looks a
> little clumsy:
>
> radix=[[]]
> for i in range(255):
> radix.append([])
>
> any better code to initalize this list?
Typically you'd say
radix = [[] for i in xrange(256)]
but what are you really doing? This plan to implement radix sorting
sounds a little bit odd, unless it's just an exercise.
You could also consider using a dictionary instead of a list,
something like:
radix = defaultdict(list)
More information about the Python-list
mailing list