A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2009-October/093351.html below:

[Python-Dev] Retrieve an arbitrary element from a set without removing it

[Python-Dev] Retrieve an arbitrary element from a set without removing it [Python-Dev] Retrieve an arbitrary element from a set without removing itStephen J. Turnbull stephen at xemacs.org
Mon Oct 26 08:48:39 CET 2009
"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


More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4