[issue18844] allow weights in random.choice

Steven Basart report at bugs.python.org
Wed Mar 30 03:11:55 EDT 2016


Steven Basart added the comment:

Hello rhettinger.  I filled out the form thanks for letting me know about it.  Is there anything else I have to do?

Hey serhiy.storchaka

There were several things "wrong" with the previous implementation in my opinion. 

1st they tried to add too much.  Which would if allowed would clutter up the random library if every function had both it's implementation as well as an accompanied generator.  The other problem being that both were attempted to be made as callable to the public API.  I would prefer the generator if present to be hidden and would also have to be more sophisticated to be able to check if it was being called with new input.

2nd by adding in the generator to the pulbic API of the random library it makes it far more confusing and obfuscates the true purpose of this function anyways which is to get a weighted choice.  

So basically there is nothing wrong with generators but they don't necessarily belong here so I removed it to try to get back to the core principles of what the function should be doing, by making it simpler.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18844>
_______________________________________


More information about the Python-bugs-list mailing list