Generator vs functools.partial?

Thomas Rachel nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de
Thu Jun 21 08:20:23 EDT 2012


Am 21.06.2012 13:25 schrieb John O'Hagan:

> But what about a generator?

Yes, but...

> def some_func():
>      arg = big_calculation()
>      while 1:
>          i = yield
>          (do_something with arg and i)
>
> some_gen = some_func()
> some_gen.send(None)
> for i in lots_of_items:
>      some_gen.send(i)

rather

def some_func(it):
     arg = big_calculation()
     for i in it:
         do_something(arg, i)

some_func(lots_of_items)


HTH,

Thomas



More information about the Python-list mailing list