[issue18844] allow weights in random.choice

Madison May report at bugs.python.org
Tue Aug 27 01:25:58 CEST 2013


Madison May added the comment:

I realize its probably quite early to begin putting a patch together, but here's some preliminary code for anyone interested.  It builds off of the "common task" example in the docs and adds in validation for the weights list.

There are a few design decisions I'd like to hash out.  
In particular: 

  - Should negative weights cause a ValueError to be raised, or should they be converted to 0s?
  - Should passing a list full of zeros as the weights arg raise a ValueError or be treated as if no weights arg was passed?

----------
keywords: +patch
Added file: http://bugs.python.org/file31479/weighted_choice.diff

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18844>
_______________________________________


More information about the Python-bugs-list mailing list