Message262656
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? |
|
Date |
User |
Action |
Args |
2016-03-30 08:56:22 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, tim.peters, rhettinger, mark.dickinson, pitrou, aisaac, westley.martinez, NeilGirdhar, madison.may, dkorchem, Christian.Kleineidam, xksteven |
2016-03-30 08:56:22 | serhiy.storchaka | set | messageid: <1459328182.12.0.00517547088348.issue18844@psf.upfronthosting.co.za> |
2016-03-30 08:56:22 | serhiy.storchaka | link | issue18844 messages |
2016-03-30 08:56:21 | serhiy.storchaka | create | |
|