any better code to initalize a list of lists?
Stargaming
stargaming at gmail.com
Sun Mar 11 15:04:50 EDT 2007
Donald Fredkin schrieb:
> 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]
>
>>> x = [[[]]*256][0]
>>> x
[[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [],
[], [], ...
>>> x[0].append(1)
>>> x
[[1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1],
[1], [1], ...
Nice one.
More information about the Python-list
mailing list