[Python-checkins] r72814 - python/branches/py3k/Doc/library/collections.rst
raymond.hettinger
python-checkins at python.org
Fri May 22 03:11:26 CEST 2009
Author: raymond.hettinger
Date: Fri May 22 03:11:26 2009
New Revision: 72814
Log:
Fix-up moving average example.
Modified:
python/branches/py3k/Doc/library/collections.rst
Modified: python/branches/py3k/Doc/library/collections.rst
==============================================================================
--- python/branches/py3k/Doc/library/collections.rst (original)
+++ python/branches/py3k/Doc/library/collections.rst Fri May 22 03:11:26 2009
@@ -455,10 +455,9 @@
# moving_average([40, 30, 50, 46, 39, 44]) --> 40.0 42.0 45.0 43.0
# http://en.wikipedia.org/wiki/Moving_average
it = iter(iterable)
- d = deque(itertools.islice(it, n))
+ d = deque(itertools.islice(it, n-1))
+ d.appendleft(0)
s = sum(d)
- if len(d) == n:
- yield s / n
for elem in it:
s += elem - d.popleft()
d.append(elem)
More information about the Python-checkins
mailing list