A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2010-December/106261.html below:

[Python-Dev] [Python-checkins] r86924 - python/branches/py3k/Doc/library/random.rst

[Python-Dev] [Python-checkins] r86924 - python/branches/py3k/Doc/library/random.rst [Python-Dev] [Python-checkins] r86924 - python/branches/py3k/Doc/library/random.rstÉric Araujo merwok at netwok.org
Thu Dec 2 13:18:53 CET 2010
> On Thu, Dec 2, 2010 at 12:41 PM, raymond.hettinger
> <python-checkins at python.org> wrote:
>> +A more general approach is to arrange the weights in a cumulative probability
>> +distribution with :func:`itertools.accumulate`, and then locate the random value
>> +with :func:`bisect.bisect`::
>> +
>> +    >>> choices, weights = zip(*weighted_choices)
>> +    >>> cumdist = list(itertools.accumulate(weights))
>> +    >>> x = random.random() * cumdist[-1]
>> +    >>> choices[bisect.bisect(cumdist, x)]
>> +    'Blue'

“pydoc bisect.bisect” is empty (“Alias for bisect_right()”); in the
code, bisect.bisect is noted as compatibility alias.  Wouldn’t it be
more helpful to use the newer name?

Regards

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4