16 Feb
2009
16 Feb
'09
11:47 a.m.
Steven D'Aprano <steve@pearwood.info> wrote:
Greg Ewing wrote:
Chris Rebert wrote:
As The Zen says: "Special cases aren't special enough to break the rules."
What might be more acceptable is to add a new method for this, with a name suggesting that it's more than just a plain mutating operation, e.g.
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)
Well, for me, What's wrong is that it's complex to write and debug, mainly. Don't you mean to say, was_it_there = (42 in myset) if not was_it_there: myset.add(42) for instance? Not that I'm pushing for the addition of this method, but I see the point. Bill