Raymond Hettinger showed a really cool way to combine collection classes:
from collections import Counter, OrderedDict class OrderedCounter(Counter, OrderedDict)
I've found a way to subclass them both, but not sure if there are bugs:
class OrderedDefaultDict(defaultdict, OrderedDict): def __init__(self, default, *args, **kwargs): defaultdict.__init__(self, default) OrderedDict.__init__(self, *args, **kwargs)