[Tutor] A faster x in S
Dinesh B Vadhia
dineshbvadhia at hotmail.com
Wed Jan 16 18:01:24 CET 2008
I used the s.intersection(t) function in the set type as it was the most appropriate. The performance was phenomenal. Thank-you!
----- Original Message -----
From: bob gailer
To: Dinesh B Vadhia
Cc: tutor at python.org
Sent: Tuesday, January 15, 2008 2:03 PM
Subject: Re: [Tutor] A faster x in S
Dinesh B Vadhia wrote:
> For some significant data pre-processing we have to perform the
> following simple process:
> Is the integer x in a list of 13K sorted integers. That's it except
> this has to be done >100m times with different x's (multiple times).
> Yep, a real pain!
> I've put the 13K integers in a list S and am using the is 'x in S'
> I was wondering if there is anything faster?
I agree with Kent.
>>> l = range(13000)
>>> import time
>>> def f(lookupVal, times, values):
.. for i in range(times):
.. z = lookupVal in values
.. return time.time()-st
So set is 1000 times faster than list!
And dict is (as expected) about the same as set.
So 100,000,000 lookups should take about 30 seconds. Not bad, eh?
Let's explore another angle. What range are the integers in (min and max)?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor