diff options
author | Raymond Hettinger <rhettinger@users.noreply.github.com> | 2019-02-15 20:40:18 (GMT) |
---|---|---|
committer | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-02-15 20:40:18 (GMT) |
commit | 9abb725cea7a1687b4d85ab9766ae6256a76a1ef (patch) | |
tree | bc804c12e1c16165429c861a638104c08f567192 /Doc/library/random.rst | |
parent | 903567e4f54494c2f4148eec0504ad761ac942c2 (diff) | |
download | cpython-9abb725cea7a1687b4d85ab9766ae6256a76a1ef.zip cpython-9abb725cea7a1687b4d85ab9766ae6256a76a1ef.tar.gz cpython-9abb725cea7a1687b4d85ab9766ae6256a76a1ef.tar.bz2 |
Improve readability of random module examples (GH-11884)
Based on reviewer feedback from Allen Downey, convert ``lambda`` to ``def``.
Diffstat (limited to 'Doc/library/random.rst')
-rw-r--r-- | Doc/library/random.rst | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/Doc/library/random.rst b/Doc/library/random.rst index a543ff0..7d051e1 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 |