Conditional “tee” with Python

This post describes the conditional tee ("ctee") module I wrote to split a sequence into two generators, according to a filter function. The problem David Beazley has a great article about generator pipelining using Python. This is a technique for handling (potentially very large) streams of data in a flexible yet efficient way. As an […]

Iterating over a window in Python

This weekend, I had a fairly common problem: given a sequence of elements and an element in that sequence, I needed to get the next element; if the element was the last in the sequence, then I needed the first element. My first stab at a solution was pretty straightforward: def item_after(elements, item):     […]