[Python-ideas] set.add() return value
greg.ewing at canterbury.ac.nz
Tue Feb 17 06:16:27 CET 2009
Guido van Rossum wrote:
> There's also the nagging concern that once we do this for set
> operations people might ask to do this for dict operations too, and
> then what's next.
I think there could be some theoretical justification
to do it for sets at least. The pattern of "if something
isn't already in some set, then add it and do some further
processing" turns up fairly frequently in various algorithms.
With dicts it's a bit different -- usually you're looking
in the dict first to get something out, and if you don't
find it, you then do something to manufacture a value and
put it in. This is covered by setdefault() or whatever the
modern replacement for it is.
More information about the Python-ideas