"jim stockford" <[EMAIL PROTECTED]> wrote
> Why is a dict lookup constant time. I.e. if there's a
> loop that walks a (shorter) list and compares each
> element with each element of a dict, what's going
> on to make this faster than an outer loop walking
> a list and an inner loop walking a secon
Jim & Jaggo -
Dict lookup is (essentially) constant-time because the hashing function
computes which unique bucket a given entry will correspond to.
(Hashing functions are usually polynomials involving prime numbers.
Can assume that the computation of the hash value is constant-time)
So there is
MAIL PROTECTED]>
>> Reply-To: [EMAIL PROTECTED]
>> To: tutor@python.org
>> Subject: Re: [Tutor] Simple way to compare Two lists
>> Date: Thu, 16 Aug 2007 10:11:14 -0700 (PDT)
>>
>> Thank you Kent, Michael, Tom and anyone else I'm forgetting who took
tem not in BigList.
[If anyone's interested, I should have the script finished and thoroughly
tested on, ah, next weekend, and I could post a link here.]
Again, Thx.
-Omer.
Message: 1
Date: Fri, 10 Aug 2007 08:11:47 -0400
From: Kent Johnson
Subject: Re: [Tutor] Simple way to compare Two lis
script finished and thoroughly
tested on, ah, next weekend, and I could post a link here.]
Again, Thx.
-Omer.
Message: 1
Date: Fri, 10 Aug 2007 08:11:47 -0400
From: Kent Johnson
Subject: Re: [Tutor] Simple way to compare Two lists
To: Tom Fitzhenry , tutor@python.org
Message-ID: <[EMAIL P
Hi,
You're really asking about optimisation incidentally.
On Friday 10 August 2007 10:54, Jaggo wrote:
> Hello!
>
> I desperately need a simple way to compare whether any item of SmallList is
> in BigList.
A simple way:
True in [x in BigList for x in SmallList]
Not efficient necessarily, but
Jaggo wrote:
> Hello!
>
> I desperately need a simple way to compare whether any item of SmallList
> is in BigList.
>
> My current way,
>
> def IsAPartOfList(SmallList,BigList)
> for item in SmallList:
> if item in BigList:
>return True
> return False
>
> Takes up waay too much tim
I think you could use sets, (I asked a similar question a few days ago
re numpy arrays).
ie
Convert both list to sets
use Set intersection
convert answer to lists
HTH
Andy
Tom Fitzhenry wrote:
> On Fri, Aug 10, 2007 at 02:54:44AM -0700, Jaggo wrote:
>> Can anyone think of any better way?
>
> If
Tom Fitzhenry wrote:
> On Fri, Aug 10, 2007 at 02:54:44AM -0700, Jaggo wrote:
>> Can anyone think of any better way?
>
> If SmallList and BigList are sorted (in order), there is a faster method:
>
> def IsAPartOfList(SmallList,BigList):
> for i in BigList:
> for j in SmallList:
>
On Fri, Aug 10, 2007 at 02:54:44AM -0700, Jaggo wrote:
> Can anyone think of any better way?
If SmallList and BigList are sorted (in order), there is a faster method:
def IsAPartOfList(SmallList,BigList):
for i in BigList:
for j in SmallList:
if i==j:
retur
Hello!
I desperately need a simple way to compare whether any item of SmallList is in
BigList.
My current way,
def IsAPartOfList(SmallList,BigList)
for item in SmallList:
if item in BigList:
return True
return False
Takes up waay too much time to process.
Can anyone think of any be
11 matches
Mail list logo