[issue7522] random.choice should accept a set as input
Michele Mazzucchi
report at bugs.python.org
Mon Apr 30 16:32:38 CEST 2012
Michele Mazzucchi <michele at buddyns.com> added the comment:
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 .
----------
nosy: +michelem
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue7522>
_______________________________________
More information about the Python-bugs-list
mailing list