[Python-ideas] set.add() return value

Terry Reedy tjreedy at udel.edu
Tue Feb 17 16:28:10 CET 2009

Greg Ewing wrote:
> Steven D'Aprano wrote:
>> It's not that saving one line is unimportant, sometimes saving one 
>> line is worth it. But there has to be a significant mental cost to 
>> that line to make it worth while
> There could be cases where the execution speed difference
> is important, especially if testing whether the element is
> in the set is expensive.
> Back when I was developing Plex, I found that the biggest
> bottleneck in building a scanner object was the NFA to
> DFA conversion. That algorithm consists almost entirely
> of testing whether things are in sets and adding them if
> they're not, and the set elements themselves are other
> sets, so they're not cheap to do membership tests on.

But why not just unconditionally add them?
Marcin just posted a nice solution for proceeding differently if really 

> If I'd had an atomic test-and-add operation for sets,
> I could imagine that part running about twice as fast
> as it did.

More information about the Python-ideas mailing list