>     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)


Raymond

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to