[Python-ideas] get method for sets?
Masklinn
masklinn at masklinn.net
Wed May 16 21:21:08 CEST 2012
On 2012-05-16, at 20:19 , Chris Rebert wrote:
> 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.
It takes the first object it finds which is pretty much solely a
property of how it stores its items, its behavior translated into Python
code is precisely:
next(iter(set))
or
list(set)[0]
I just tested creating a few thousand sets and filling them with random
integer values (using arc4random(3)) and never once did [set anyObject]
differ from [[set allObjects] objectAtIndex:0] or from
[[set objectEnumerator] nextValue].
More information about the Python-ideas
mailing list