Feature Requests item #1212091, was opened at 2005-05-31 17:54
Message generated for change (Comment added) made by birkenfeld
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1212091&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Mike Coleman (mkc)
Assigned to: Nobody/Anonymous (nobody)
Summary: sets needs an 'arbitrary element' method

Initial Comment:
It would be nice to have an "arbitrary element" method
that would return some arbitrary element of a non-empty
set (throwing an exception if the set is empty). 
Something like this

>>> s = sets.Set([1,2,3])
>>> print s.element()
2

AFAIK, the current alternative would be to do something
like this

>>> print list(s)[0]

which is somewhat expensive and unreadable.

It'd be fine if the operator returned the same or a
different element each time.  Perhaps it'd be useful if
it returned the same element each time for frozen sets.

----------------------------------------------------------------------

>Comment By: Reinhold Birkenfeld (birkenfeld)
Date: 2005-05-31 17:59

Message:
Logged In: YES 
user_id=1188172

For mutable sets, I think that pop() is better suited. Do
you have a use case of your proposal with frozensets?

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1212091&group_id=5470
_______________________________________________
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to