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

Greg Ewing greg.ewing at canterbury.ac.nz
Sat Feb 14 02:44:17 CET 2009

Steven D'Aprano wrote:
> Greg Ewing wrote:
>>   was_it_there = myset.test_and_add(42)
> What's the use-case for this? What's wrong with doing this?
> if 42 in myset:
>     myset.add(42)

Nothing, other than it feels a little bit wrong looking
the value up twice when once would be enough.

I'm not particularly worried about this, I was just
pointing out that adding a new method would be less
of a violation of the Zen than changing an existing


More information about the Python-ideas mailing list