Generator Example

Question

Generator Example with a conditional.

Solution

def foo(n):
    if (n < 3):
        yield 1
    else:
        return
    yield 2
Run this
Comments by Disqus