[Python-checkins] Improve readability of random module examples (GH-11884) (GH-11885)

Raymond Hettinger webhook-mailer at python.org
Fri Feb 15 15:47:07 EST 2019


https://github.com/python/cpython/commit/7a3cbcdc55cb89ae69e47bff0df188610b53ec89
commit: 7a3cbcdc55cb89ae69e47bff0df188610b53ec89
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: Raymond Hettinger <rhettinger at users.noreply.github.com>
date: 2019-02-15T12:47:04-08:00
summary:

Improve readability of random module examples (GH-11884) (GH-11885)

Based on reviewer feedback from Allen Downey, convert ``lambda`` to ``def``.
(cherry picked from commit 9abb725cea7a1687b4d85ab9766ae6256a76a1ef)

Co-authored-by: Raymond Hettinger <rhettinger at users.noreply.github.com>

files:
M Doc/library/random.rst

diff --git a/Doc/library/random.rst b/Doc/library/random.rst
index a543ff016a62..7d051e185429 100644
--- a/Doc/library/random.rst
+++ b/Doc/library/random.rst
@@ -385,12 +385,16 @@ Simulations::
 
    >>> # Estimate the probability of getting 5 or more heads from 7 spins
    >>> # of a biased coin that settles on heads 60% of the time.
-   >>> trial = lambda: choices('HT', cum_weights=(0.60, 1.00), k=7).count('H') >= 5
+   >>> def trial():
+   ...     return choices('HT', cum_weights=(0.60, 1.00), k=7).count('H') >= 5
+   ...
    >>> sum(trial() for i in range(10000)) / 10000
    0.4169
 
    >>> # Probability of the median of 5 samples being in middle two quartiles
-   >>> trial = lambda : 2500 <= sorted(choices(range(10000), k=5))[2]  < 7500
+   >>> def trial():
+   ...     return 2500 <= sorted(choices(range(10000), k=5))[2] < 7500
+   ...
    >>> sum(trial() for i in range(10000)) / 10000
    0.7958
 



More information about the Python-checkins mailing list