report at bugs
Apr 30, 2012, 7:32 AM
Post #1 of 2
Michele Mazzucchi <michele [at] buddyns> added the comment:
[issue7522] random.choice should accept a set as input
Folks, I really think this should be addressed.
Python has beautiful data structure semantics, and this is a stain in them.
An implementation based on the current underlying hash table is quite simple, just pick random addresses until an active key is found. Even on sparse tables this is probabilistic O(1). Even with average load factor = 50%, only 1 extra attempt is needed; 2 with LF as low as 33%.
I'm happy to provide a patch if anyone defines the desired API in Include/setobject.h .
Python tracker <report [at] bugs>
Python-bugs-list mailing list