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.

Regarding efficiency, simple operations such as moving averages can be improved tremendously using double-ended queues, or deques. Oddly enough, it is pronounced "deck". Deques are another friend of the engineer, as they make a simple FIFO buffer. Lists can be used as a crude FIFO, but they do not scale well. Adding new elements to a list with .append() is O(1). But using .pop(0) to remove the oldest element is O(n). For deques, the equivalent of both are O(1). Here's how to computer a moving average using a deque.

Name:
Mail: (not shown)

Please type this: