Populating a dictionary, fast

Arkanes arkanes at gmail.com
Sun Nov 11 19:42:08 CET 2007


Michael Bacarella wrote:
> 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
>
>   
It takes about 20 seconds for me. It's possible it's related to int/long 
unification - try using Python 2.5. If you can't switch to 2.5, try 
using string keys instead of longs.



More information about the Python-list mailing list