[Python-ideas] set.add(x) slower than if x in set:set.add(x)

Gerald Britton gerald.britton at gmail.com
Mon Sep 14 17:03:15 CEST 2009

Aha ok, so cheap inserts, not so cheap lookups (especially if not found)

On Mon, Sep 14, 2009 at 10:26 AM, Daniel Stutzbach
<daniel at stutzbachenterprises.com> wrote:
> On Mon, Sep 14, 2009 at 9:19 AM, Gerald Britton <gerald.britton at gmail.com>
> wrote:
>> assuming that set.add() takes close to the same time whether the item
>> is in the set or not (in reality I suppose that it needs to play with
>> a few pointers if the item is not in the set and may need to rebalance
>> the tree, if it is a red-black tree or something similar -- what is
>> it, actually?)
> Under the hood, the set type uses a hash table.
> --
> Daniel Stutzbach, Ph.D.
> President, Stutzbach Enterprises, LLC

Gerald Britton

More information about the Python-ideas mailing list