Expression can be simplified on list

Peter Otten __peter__ at web.de
Thu Sep 29 08:11:07 EDT 2016


MRAB wrote:

> What if an _exhausted_ iterator was falsey?

Many would expect

it = iter("abc")
while it:
    print(next(it))

to work (i. e. no StopIteration) -- if it doesn't, what's the actual 
usecase?

If it does work there must be some lookahead which not all iterators can 
provide in a meaningful way:

it = iter(time.time, None)
while it:
   time.sleep(...)
   print("Now", next(it))




More information about the Python-list mailing list