Commit 6c01ebcc authored by Raymond Hettinger's avatar Raymond Hettinger Committed by GitHub

bpo-37158: Simplify and speed-up statistics.fmean() (GH-13832)

parent ccf0efbb
...@@ -320,11 +320,11 @@ def fmean(data): ...@@ -320,11 +320,11 @@ def fmean(data):
except TypeError: except TypeError:
# Handle iterators that do not define __len__(). # Handle iterators that do not define __len__().
n = 0 n = 0
def count(x): def count(iterable):
nonlocal n nonlocal n
n += 1 for n, x in enumerate(iterable, start=1):
return x yield x
total = fsum(map(count, data)) total = fsum(count(data))
else: else:
total = fsum(data) total = fsum(data)
try: try:
......
Speed-up statistics.fmean() by switching from a function to a generator.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment