In <[EMAIL PROTECTED]>, Justin  Azoff
wrote:

> Rhamphoryncus wrote:
> [snip interesting istep function]
> 
>> Would anybody else find this useful?  Maybe worth adding it to itertool?
> 
> yeah, but why on earth did you make it so complicated?
> 
> def istep(iterable, step):
>     a=[]
>     for x in iterable:
>         if len(a) >= step:
>             yield a
>             a=[]
>         a.append(x)
>     if a:
>         yield a

This is not as "lazy" as Rhamphoryncus' function anymore.  Lets say the
`iterable` is a stream of events, then your function always needs to
"receive" `step` events before the caller can do anything else with the
events.  In Rhamphoryncus' function the caller can react on the event as
soon as it's "delivered" by `iterable`.

Ciao,
        Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to