def exhaustcall(call, iterable, exception=StopIteration, _n=next): ''' call function on an iterator until it's exhausted @param call: call that does the exhausting @param iterable: iterable to exhaust @param exception: exception marking end of iteration ''' iterable = map(call, iterable) try: while True: _n(iterable) except exception: pass
def __repr__(self): if not self: return '%s()' % self.__class__.__name__ items = ', '.join(map('%r: %r'.__mod__, self.most_common())) return '%s({%s})' % (self.__class__.__name__, items)