[issue33494] random.choices ought to check that cumulative weights are in ascending order

Raymond Hettinger report at bugs.python.org
Tue May 15 06:58:18 EDT 2018


Raymond Hettinger <raymond.hettinger at gmail.com> added the comment:

I concur with Serhiy.  The proposed check would cripple the intended use of cumulative weights which is provided as a way to avoid the cost of rebuilding the weights on every call.  FWIW, bisect() has a long history of requiring sorted inputs and has a similar possibility of misuse, but it too would cripple its core use case if it were to have to validate that the user input was sorted.

I'm open to a docs change but am dubious that that would have helped the OP on python-ideas.  The docs already have a specific example showing the relationship between weights and cum_weights, as well as indicating that the purpose of cum_weights is to save the work of computing the weights accumulation.  There is an additional example in the recipes section.

----------
assignee:  -> rhettinger
components: +Documentation -Library (Lib)

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33494>
_______________________________________


More information about the Python-bugs-list mailing list