need optimizing help

Riccardo Galli riccardo_cut-me at cut.me.sideralis.net
Sat Mar 13 14:22:51 EST 2004


On Sat, 13 Mar 2004 10:07:54 -0800, rabbits77 wrote:

> I have a dictionary with a very very large(possibly millions) of
> key/value pairs.
> The key is a tuple that looks like (id,date)
> What is the fastest way to get out all of the values that match any
> key given that they individual key elements are coming from two
> seperate lists?
> The approach of
> for id in IDS:
>     for date in dates:
>         data=myDict[(id,date)]
> 
> seems to just take too long. Is there a speedier, more pythonic, way
> of doing this? Any help speeding this up would be much appreciated!!

if IDS and dates lenght is the same, you could write
for i in enumerate(IDS):
    data=myDict[(IDS[i],dates[i])]

which is more good looking, but I think performances are similar.

my 2 cents.

Riccardo



More information about the Python-list mailing list