Loop until condition is true

Jeff Epler jepler at unpythonic.net
Wed Jun 22 12:50:01 EDT 2005


def until(pred):
    yield None
    while True:
        if pred(): break
        yield None

def example():
    i = 0
    for _ in until(lambda: x==0):
        x = 10 - i
        i += 1
        print x, i

example()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20050622/b8802b6d/attachment.sig>


More information about the Python-list mailing list