Populating a dictionary, fast

Michael Bacarella mbac at gpshopper.com
Sun Nov 11 17:51:37 CET 2007

> > 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:

and see it take about 45 minutes with this:

$ cat cache-keys.py
v = {}
for line in open('keys.txt'):
        v[long(line.strip())] = True

More information about the Python-list mailing list