Last iteration?
Hendrik van Rooyen
mail at microcorp.co.za
Thu Oct 18 02:36:24 EDT 2007
"Raymond Hettinger" <pyt...cn.com> wrote:
> 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)
If this is what you call straightforward - heaven forfend
that I ever clap my orbs on something you call convoluted!
:-)
Faced with this problem, I would probably have used
enumerate with a look ahead and the IndexError would
have told me I am at the end...
- Hendrik
More information about the Python-list
mailing list