Populating a dictionary, fast
Ricardo Aráoz
ricaraoz at gmail.com
Sun Nov 11 14:18:55 EST 2007
Michael Bacarella wrote:
>>> This would seem to implicate the line id2name[id] = name as being
> excruciatingly slow.
>> As others have pointed out there is no way that this takes 45
>> minutes.Must be something with your system or setup.
>>
>> A functionally equivalent code for me runs in about 49 seconds!
>> (it ends up using about twice as much ram as the data on disk)
>
> You can download the list of keys from here, it's 43M gzipped:
> http://www.sendspace.com/file/9530i7
>
> and see it take about 45 minutes with this:
>
> $ cat cache-keys.py
> #!/usr/bin/python
> v = {}
> for line in open('keys.txt'):
> v[long(line.strip())] = True
Have you tried taking the long away? I mean :
v[line.strip()] = True
More information about the Python-list
mailing list