Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9abb725

Browse files
rhettingermiss-islington
authored andcommitted
Improve readability of random module examples (GH-11884)
Based on reviewer feedback from Allen Downey, convert ``lambda`` to ``def``.
1 parent 903567e commit 9abb725

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

Doc/library/random.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,12 +385,16 @@ Simulations::
385385

386386
>>> # Estimate the probability of getting 5 or more heads from 7 spins
387387
>>> # of a biased coin that settles on heads 60% of the time.
388-
>>> trial = lambda: choices('HT', cum_weights=(0.60, 1.00), k=7).count('H') >= 5
388+
>>> def trial():
389+
... return choices('HT', cum_weights=(0.60, 1.00), k=7).count('H') >= 5
390+
...
389391
>>> sum(trial() for i in range(10000)) / 10000
390392
0.4169
391393

392394
>>> # Probability of the median of 5 samples being in middle two quartiles
393-
>>> trial = lambda : 2500 <= sorted(choices(range(10000), k=5))[2] < 7500
395+
>>> def trial():
396+
... return 2500 <= sorted(choices(range(10000), k=5))[2] < 7500
397+
...
394398
>>> sum(trial() for i in range(10000)) / 10000
395399
0.7958
396400

0 commit comments

Comments
 (0)