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 NeilGirdhar, aisaac, madison.may, mark.dickinson, pitrou, rhettinger, serhiy.storchaka, tim.peters, westley.martinez
Date 2013-09-24.21:26:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1380057964.59.0.427175348891.issue18844@psf.upfronthosting.co.za>
In-reply-to
Content
Most existing implementation produce just index. That is why weighted_choice() accepts singular weights list and returns index. On the other hand, I think working with mapping will be wished feature too (especially because Counter is in stdlib). Indexable sequences and mappings are similar. In both cases weighted_choice() returns value which can be used as index/key of input argument.

If you need choice an element from some sequence, just use seq[weighted_choice(weights)]. Actually weighted_choice() has no common code with choice() and has too different use cases. They should be dissimilar as far as possible. Perhaps we even should avoid the "choice" part in function names (are there any ideas?) to accent this.
History
Date User Action Args
2013-09-24 21:26:04serhiy.storchakasetrecipients: + serhiy.storchaka, tim.peters, rhettinger, mark.dickinson, pitrou, aisaac, westley.martinez, NeilGirdhar, madison.may
2013-09-24 21:26:04serhiy.storchakasetmessageid: <1380057964.59.0.427175348891.issue18844@psf.upfronthosting.co.za>
2013-09-24 21:26:04serhiy.storchakalinkissue18844 messages
2013-09-24 21:26:04serhiy.storchakacreate