Most efficient solution?

Terry Reedy tjreedy at
Sat Jul 21 07:47:16 CEST 2001

"Christopher A. Craig" <com-nospam at> wrote in message
news:mailman.995674715.6446.python-list at
> Hash: SHA1
> "Terry Reedy" <tjreedy at> writes:
> > To compare program running times, they should compute the same
> >
> > How long does dict2 take if you remove the not, so it makes the
> > of 1500 elements that revised dict does, instead of the 'not' list
> > 6000?
> >
> > How long does dict take if you feed filter with 'lambda x,
> > f=c.has_key: f(x)', so it make the 'not' list of 6000 elements?
> >
> dict2 without the not takes (predictably) about twice as long as
> (.038 seconds vs. .019) (because the explicit loops in the list
> comprehensions are slower)
> dict with a not takes (also predictably) slightly longer than dict2
> (.06 vs .055) (because the overhead of a lambda is higher than the
> My point was not to compare dict to dict2, but to show that the
> original author's comp() was greatly outperformed by a proper
> dictionary solution.

I know this was not your main point, so thank you for running these.
I'm going to replace 1.5.2 with 2.1.1 soon, so could not do this
myself yet.  Your result is about what I expected based on previous

TJ Reedy

More information about the Python-list mailing list