Last iteration?

Raymond Hettinger python at rcn.com
Wed Oct 17 18:45:57 EDT 2007


[Paul Hankin]
> def lastdetector(iterable):
>     t, u = tee(iterable)
>     return izip(chain(imap(lambda x: False, islice(u, 1, None)),
>         [True]), t)

Sweet!  Nice, clean piece of iterator algebra.

We need a C-speed verion of the lambda function, something like a K
combinator that consumes arguments and emits constants.


Raymond






More information about the Python-list mailing list