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

Greg Ewing greg.ewing at canterbury.ac.nz
Tue Feb 17 09:57:35 CET 2009

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.

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