any better code to initalize a list of lists?

Bart Willems b.r.willems at gmail.com
Sun Mar 11 20:12:04 CET 2007


Donald Fredkin wrote:
> John wrote:
> 
>> 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?
> 
> radix = [[[]]*256][0]
> 

No I fell for that one too - it's the same as 'radix = [[]] * 256. Try 
radix[0].append('dead parrot')..



More information about the Python-list mailing list