Skip to content

Commit

Permalink
bpo-37158: Simplify and speed-up statistics.fmean() (GH-13832)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhettinger committed Jun 5, 2019
1 parent ccf0efb commit 6c01ebc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Lib/statistics.py
Expand Up @@ -320,11 +320,11 @@ def fmean(data):
except TypeError:
# Handle iterators that do not define __len__().
n = 0
def count(x):
def count(iterable):
nonlocal n
n += 1
return x
total = fsum(map(count, data))
for n, x in enumerate(iterable, start=1):
yield x
total = fsum(count(data))
else:
total = fsum(data)
try:
Expand Down
@@ -0,0 +1 @@
Speed-up statistics.fmean() by switching from a function to a generator.

0 comments on commit 6c01ebc

Please sign in to comment.