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/093407.html below:

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

[Python-Dev] Retrieve an arbitrary element from a set withoutremoving it [Python-Dev] Retrieve an arbitrary element from a set withoutremoving itTerry Reedy tjreedy at udel.edu
Tue Oct 27 19:50:28 CET 2009
Raymond Hettinger wrote:
>
> A dict.get() can be meaningfully used in a loop (because the key can vary).
> A set.get() returns the same value over and over again (because there is 
> no key).

There are two ideas of set.get floating about:
1) get an arbitrary object
2) get the object in the set with the same 'value'(hash+eq) as an input 
arg (the intern case). In this case, there is a 'key', even if it is 
somewhat abstract rather that being an object.

Both could be done with the same method, depending on whether an arg is 
passed or not. The former is not useful in a loop; the latter could be.

If there is no match in case 2, the method could a) raise an exception, 
b) return None (which by its nature would never sensibly be looked up), 
or c) return an object specified by 'default=xxx' keyword arg.

Terry Jan Reedy

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