On Oct 17, 8:16 am, Raymond Hettinger <[EMAIL PROTECTED]> wrote: > > def lastdetecter(iterable): > > "fast iterator algebra" > > lookahead, t = tee(iterable) > > lookahead.next() > > t = iter(t) > > return chain(izip(repeat(False), imap(itemgetter(1), > > izip(lookahead, t))), izip(repeat(True),t)) > > More straight-forward version: > > def lastdetecter(iterable): > t, lookahead = tee(iterable) > lookahead.next() > return izip(chain(imap(itemgetter(0), izip(repeat(False), > lookahead)), repeat(True)), t)
def lastdetector(iterable): t, u = tee(iterable) return izip(chain(imap(lambda x: False, islice(u, 1, None)), [True]), t) -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list