View gist:5805014
import itertools | |
def iter_interleave(*args): | |
iterators = [(x for x in it) for it in args] | |
has_values = [True for _ in xrange(len(iterators))] | |
while max(has_values): | |
for it, has_value, i in itertools.izip(iterators, has_values, xrange(len(iterators))): | |
if has_value: | |
try: | |
value = it.next() |
View reducing_dict.py
class ReducingDict(dict): | |
def __init__(self, function, initial = None): | |
self._function = function | |
self._initial = initial | |
super(ReducingDict, self).__init__() | |
def __setitem__(self, key, new_value): | |
if key in self: |
View gist:2863226
import copy | |
class ReducingDict(dict): | |
def __init__(self, function, initial = None): | |
self._function = function | |
self._initial = initial | |
super(ReducingDict, self).__init__() | |
def __setitem__(self, key, new_value): |