[Python-ideas] get method for sets?
Ethan Furman
ethan at stoneleaf.us
Thu May 17 01:08:59 CEST 2012
Steven D'Aprano wrote:
> Mike Meyer wrote:
>
>> But my question was actually whether or not there was a reason for it
>> not existing. Has there been a previous discussion of this?
>
>
> Aye yai yai, have there ever.
>
> http://mail.python.org/pipermail/python-bugs-list/2005-August/030069.html
>
> If you have an hour or two spare, read this thread:
>
> http://mail.python.org/pipermail/python-dev/2009-October/093227.html
>
> By the way, I suggest that a better name than "get" is pick(), which
> once was (but no longer is) suggested by Wikipedia as a fundamental set
> operation.
>
> http://en.wikipedia.org/w/index.php?title=Set_%28abstract_data_type%29&oldid=461872038#Static_sets
>
>
>
> It seems to me that it has been removed because:
>
> - the actual semantics of what it means to get/pick a value from
> a set are unclear; and
> - few, if any, set implementations actually provide this method.
>
> I still think your best bet is a helper function:
>
> def pick(s):
> return next(iter(s))
Don't forget the doc string!
"returns an arbitrary element from set s"
~Ethan~
More information about the Python-ideas
mailing list