[Python-Dev] Retrieve an arbitrary element from a set withoutremoving it (original) (raw)
Yuvgoog Greenle ubershmekel at gmail.com
Tue Nov 3 09:20:52 CET 2009
- Previous message: [Python-Dev] Retrieve an arbitrary element from a set withoutremoving it
- Next message: [Python-Dev] Retrieve an arbitrary element from a set withoutremoving it
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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:
- 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
- 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>
- Previous message: [Python-Dev] Retrieve an arbitrary element from a set withoutremoving it
- Next message: [Python-Dev] Retrieve an arbitrary element from a set withoutremoving it
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]