https://github.com/python/cpython/commit/cc5cd4d93e3e079e897da9ceb1732ef16d79d01b
commit: cc5cd4d93e3e079e897da9ceb1732ef16d79d01b
branch: main
author: Raymond Hettinger <[email protected]>
committer: rhettinger <[email protected]>
date: 2024-05-31T17:08:55-05:00
summary:
statistics.fmean(): speed-up code path for non-sizeable inputs. (gh-119876)
files:
M Lib/statistics.py
diff --git a/Lib/statistics.py b/Lib/statistics.py
index c2f4fe8e054d3d..450edfaabe8def 100644
--- a/Lib/statistics.py
+++ b/Lib/statistics.py
@@ -505,13 +505,11 @@ def fmean(data, weights=None):
n = len(data)
except TypeError:
# Handle iterators that do not define __len__().
- n = 0
- def count(iterable):
- nonlocal n
- for n, x in enumerate(iterable, start=1):
- yield x
- data = count(data)
- total = fsum(data)
+ counter = count()
+ total = fsum(map(itemgetter(0), zip(data, counter)))
+ n = next(counter)
+ else:
+ total = fsum(data)
if not n:
raise StatisticsError('fmean requires at least one data point')
return total / n
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]