This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients Christian.Kleineidam, NeilGirdhar, aisaac, dkorchem, madison.may, mark.dickinson, pitrou, rhettinger, serhiy.storchaka, tim.peters, westley.martinez, xksteven
Date 2016-03-30.08:56:21
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1459328182.12.0.00517547088348.issue18844@psf.upfronthosting.co.za>
In-reply-to
Content
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?
History
Date User Action Args
2016-03-30 08:56:22serhiy.storchakasetrecipients: + serhiy.storchaka, tim.peters, rhettinger, mark.dickinson, pitrou, aisaac, westley.martinez, NeilGirdhar, madison.may, dkorchem, Christian.Kleineidam, xksteven
2016-03-30 08:56:22serhiy.storchakasetmessageid: <1459328182.12.0.00517547088348.issue18844@psf.upfronthosting.co.za>
2016-03-30 08:56:22serhiy.storchakalinkissue18844 messages
2016-03-30 08:56:21serhiy.storchakacreate