[Python-ideas] get method for sets?

Chris Rebert pyideas at rebertia.com
Wed May 16 20:19:05 CEST 2012


On Wed, May 16, 2012 at 9:20 AM, Steven D'Aprano <steve at pearwood.info> 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.

Objective-C's NSSet calls it "anyObject" and doesn't specify much
about it (in particular, its behavior when called repeatedly), mainly
just that "the selection is not guaranteed to be random". I haven't
poked around to see how it actually behaves in practice.

C#'s ISet has First() and Last(), but merely as extension methods.

Java, Ruby, and Haskell don't seem to include any such operation in
their generic set interfaces.

Cheers,
Chris
--
http://rebertia.com



More information about the Python-ideas mailing list