[Python-checkins] Small speed-up for NormalDist.samples (GH-94730)

rhettinger webhook-mailer at python.org
Sun Jul 10 23:35:03 EDT 2022


https://github.com/python/cpython/commit/c9118afd045a64ca22d4a8cc5d43532607083b2d
commit: c9118afd045a64ca22d4a8cc5d43532607083b2d
branch: main
author: Raymond Hettinger <rhettinger at users.noreply.github.com>
committer: rhettinger <rhettinger at users.noreply.github.com>
date: 2022-07-10T22:34:53-05:00
summary:

Small speed-up for NormalDist.samples (GH-94730)

files:
M Lib/statistics.py

diff --git a/Lib/statistics.py b/Lib/statistics.py
index 2d66b0522f19d..a2793d9718686 100644
--- a/Lib/statistics.py
+++ b/Lib/statistics.py
@@ -1193,7 +1193,7 @@ def samples(self, n, *, seed=None):
         "Generate *n* samples for a given mean and standard deviation."
         gauss = random.gauss if seed is None else random.Random(seed).gauss
         mu, sigma = self._mu, self._sigma
-        return [gauss(mu, sigma) for i in range(n)]
+        return [gauss(mu, sigma) for _ in repeat(None, n)]
 
     def pdf(self, x):
         "Probability density function.  P(x <= X < x+dx) / dx"



More information about the Python-checkins mailing list