array of array of float

Schüle Daniel uval at rz.uni-karlsruhe.de
Sun Jul 9 16:35:09 EDT 2006


Schüle Daniel schrieb:
> Summercoolness at gmail.com schrieb:
>> i used C too much and haven't used Python for a while...
>>
>> like in C, if we want an array of array of float, we use
>>
>> float a[200][500];
>>
>> now in Python, seems like we have to do something like
>>
>> a = [ [ ] ] * 200
>>
>> and then just use
>>
>> a[1].append(12.34)   etc
>>
>> but it turns out that all 200 elements points to the same list...
>> and i have to use
>>
>> a = [ ]
>> for i in range (0, 200):
>>     a.append([ ])
>>
>> is there a simpler way... i wonder...
> 
> a = [[] for in range(200)]

correction :)

a = [[] for i in range(200)]



More information about the Python-list mailing list