
26 Oct
2009
26 Oct
'09
8:48 a.m.
"Martin v. Löwis" writes:
res.get() would be a fairly obvious way to do it. Enough that I would probably never have gone searching for any of the other answers. Though personally, I think I would call it "set.peek()", but the specific name doesn't really matter to me.
Somebody proposed to call it .any(); this I like best (except that one might expect that any takes a predicate as the argument).
Why not allow that?
def any(self, predicate=lambda x: True, default=None) for a in self: if predicate(a): break else: return default return a