[EMAIL PROTECTED] wrote: > I have modified, simplified and (hopefully) improved Steven's code > like this (but it may be a bit slower, because the class It is inside > the function?):
Here is a yet more simple version, I wonder if it still does the same thing, whatever it is you are looking for :-) def xsplitter(iseq, pred): class It(object): def __init__(self, fun, parity): self.divert = fun self.parity = parity self.queue = collections.deque() def append(self, item): self.queue.append(item) def __iter__(self): while self.queue: yield self.queue.popleft() for item in iseq: if pred(item) == self.parity: yield item else: self.divert(item) for x in self: yield x it1 = It(lambda y: it2.append(y), True) it2 = It(lambda y: it1.append(y), False) return it1, it2 A. -- http://mail.python.org/mailman/listinfo/python-list