Populating a dictionary, fast [SOLVED SOLVED]

Michael Bacarella mbac at gpshopper.com
Mon Nov 12 12:46:32 EST 2007


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

Yes, this was it.  It ran *very* fast on Python v2.5.

Terribly on v2.4, v2.3.

(I thought I had already evaluated v2.5 but I see now that the server
With 2.5 on it invokes 2.3 for 'python'.)

Thanks!




More information about the Python-list mailing list