Performance: sets vs dicts.

Arnaud Delobelle arnodel at googlemail.com
Sun Aug 29 21:24:04 CEST 2010


John Nagle <nagle at animats.com> writes:

>    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.
>
> 				John Nagle

IIRC Frozensets are implemented more or less as sets with a hash
function and immutability so I would expect "in" to perform exactly the
same as for sets.  For dicts, I would think that the set implementation
is very close to the dict one.

So I wouldn't expect any significant difference between any of them.

-- 
Arnaud



More information about the Python-list mailing list