From: Raymond Hettinger Date: Fri, 22 May 2009 01:11:26 +0000 (+0000) Subject: Fix-up moving average example. X-Git-Tag: v3.1rc1~91 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d40285a986990d45c29e83943dc7783a4e976da5;p=thirdparty%2FPython%2Fcpython.git Fix-up moving average example. --- diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst index 3f5734884e6e..4c64d6144c1b 100644 --- a/Doc/library/collections.rst +++ b/Doc/library/collections.rst @@ -455,10 +455,9 @@ added elements by appending to the right and popping to the left:: # 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)