Serhiy Storchaka added the comment:

I disagree.

My patch adds two functions because they serve two different purposes. 
weighted_choice() returns one random value as other functions in the random 
module. weighted_choice_generator() provides more efficient way to generate 
random values, since startup cost is more significant than for other random 
value generators. Generators are widely used in Python, especially in Python 3. 
If they considered confusing, we should deprecate builtins map(), filter(), 
zip() and the itertools module at first place.

Your function, Steven, returns a list containing one random value by default. 
It does not match the interface of other functions in the random module. It 
matches the interface of NumPy random module. In Python you need two separate 
functions, one that returns single value,  and other that returns a list of 
values. But returning iterator and generating values by demand is more 
preferable in Python 3. Generatorsa are more flexible. With 
weighted_choice_generator() it is easy to get the result of your function: 
list(islice(weighted_choice_generator(data), amount)). But generating dynamic 
amount of values with your interface is impossible.

Raymond, if you have now free time, could you please make a review of 
weighted_choice_generator_2.patch?

----------
keywords: +needs review
versions: +Python 3.6 -Python 3.5

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue18844>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to