Re: Automatically advancing a bi-directional generator to the point of accepting a non-None value?

2020-11-22 Thread Dieter Maurer
Go Luhng wrote at 2020-11-21 14:30 -0500: >Suppose we write a very simple bi-directional generator in Python: > >def share_of_total(): >s = 0 >new_num = 0 >while True: >new_num = yield new_num / (s or 1) >s += new_num > >share_calculator =

Automatically advancing a bi-directional generator to the point of accepting a non-None value?

2020-11-21 Thread Go Luhng
Suppose we write a very simple bi-directional generator in Python: def share_of_total(): s = 0 new_num = 0 while True: new_num = yield new_num / (s or 1) s += new_num share_calculator = share_of_total() next(share_calculator) # Without