for(i=0;True;i++) in python?

python

Solution

You could make use of `itertools`:

from itertools import takewhile, count

# ...
def myfunc():
    return takewhile(lambda x: x is not None, (lookup(i) for i in count(1)))

If you don't like `takewhile` for whatever reason:

for i in count(1):
     res = lookup(i)
     if res is None: break
     yield res

Problem

Is there a more pythonic way, or at least a shorter and simpler way, to do this: ``` i = 1 while True: res = lookup(i) # returns a value or None if res is None: break else: i += 1 yield res ```

Original source