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

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

[Python-Dev] Retrieve an arbitrary element from a set withoutremoving itYuvgoog Greenle ubershmekel at gmail.com
Tue Nov 3 09:20:52 CET 2009
On Tue, Nov 3, 2009 at 12:19 AM, Greg Ewing <greg.ewing at canterbury.ac.nz>wrote:

> Cameron Simpson wrote:
>
>  Personally, I'm for the iteration spec in a lot of ways.
>>
>> Firstly, a .get()/.pick() that always returns the same element feels
>> horrible. Is there anyone here who _likes_ it?
>>
>
>
State might cause people to use this to iterate which would be just plain
wrong. The 2 things I have a bad feeling about is:
1. random.choice could be a pythonic alternative to what some have mentioned
here but it doesn't work on sets. The following code raises TypeError: 'set'
object does not support indexing:
    import random
    random.choice(set([1,2,3,4,5,6]))
this is kinda ironic: http://en.wikipedia.org/wiki/Axiom_of_choice
2. If I store objects in a set and modify their attributes I have no O(1)
way of getting the objects back if I stumble upon an equivalent object. In
cases like that I'd have to either iterate over the set or use a dict with
key == value. I have a feeling the "get" or "peek" api could cater to this
need. A use case for this could be an implementation of a cookie jar with a
set of cookies where equivalence is defined by the name and domain.

--yuv
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20091103/3163271b/attachment.htm>
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