Performance: sets vs dicts.

Aahz aahz at
Mon Aug 30 15:03:02 CEST 2010

In article <f11e1bba-3846-41c0-a789-5fc799335369 at>,
Raymond Hettinger  <python at> wrote:
>On Aug 29, 12:12=A0pm, John Nagle <na... at> wrote:
>> Is the "in" test faster for a dict or a set?  Is "frozenset" faster
>> than "set"? Use case is for things like applying "in" on a list of
>> 500 or so words while checking a large body of text.
>There is no significant difference.  All three are implemented using
>substantially the same code.

That reminds me: one co-worker (who really should have known better ;-)
had the impression that sets were O(N) rather than O(1).  Although
writing that off as a brain-fart seems appropriate, it's also the case
that the docs don't really make that clear, it's implied from requiring
elements to be hashable.  Do you agree that there should be a comment?
Aahz (aahz at           <*>

"...if I were on life-support, I'd rather have it run by a Gameboy than a
Windows box."  --Cliff Wells

More information about the Python-list mailing list