[issue40569] Add optional weights to random.sample()

2020-05-10 Thread David Heiberg
David Heiberg added the comment: Ahh I see, thanks for clearing that up! On Sun, May 10, 2020, 04:41 Raymond Hettinger wrote: > > Raymond Hettinger added the comment: > > Negative weights are undefined for choices() as well. Just like bisect() > and merge() don't verify their inputs are so

[issue40569] Add optional weights to random.sample()

2020-05-09 Thread Raymond Hettinger
Raymond Hettinger added the comment: Negative weights are undefined for choices() as well. Just like bisect() and merge() don't verify their inputs are sorted. Usually, full scan precondition checks are expensive in pure python and aren't worth penalizing correct code. As Henk-Jaap points-

[issue40569] Add optional weights to random.sample()

2020-05-09 Thread Henk-Jaap Wagenaar
Henk-Jaap Wagenaar added the comment: @rhettinger: I like this proposal. @dheiberg: to me, it seems negative weights are explicitly not supported, from: https://docs.python.org/3/library/random.html#random.choices "Weights are assumed to be non-negative." Unless I am missing something. In m

[issue40569] Add optional weights to random.sample()

2020-05-09 Thread David Heiberg
David Heiberg added the comment: Just playing around with this and I think one thing to consider is how to handle negative weights. Should they even be allowed? One interesting behaviour I encountered with the current draft is the following: >>> r.sample(['katniss', 'prim', 'gale', 'peet

[issue40569] Add optional weights to random.sample()

2020-05-08 Thread Raymond Hettinger
Change by Raymond Hettinger : -- keywords: +patch pull_requests: +19325 stage: -> patch review pull_request: https://github.com/python/cpython/pull/20014 ___ Python tracker __

[issue40569] Add optional weights to random.sample()

2020-05-08 Thread Raymond Hettinger
New submission from Raymond Hettinger : Weighted sampling without replacement isn't easy for a user to do with the current tooling. There is a StackOverflow question about how to do it. Also, this service is currently offered by numpy. Use it like this: >>> sample(['katniss', 'prim', 'g