Generators for Engineers

A gentle introduction to infinite sequences.

Comments are moderated. It may take a few minutes before your comment appears.
Markdown is supported in your comments.

def moving_average(data_list):
    previous = 0
    for datum in data_list:
        yield (datum - previous) * 0.5
        previous = datum

>>> list(moving_average(xrange(10)))
[0.0, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5]
Name:
Mail: (not shown)

Please type this: