Quick actions

cmd+k|ctrl+k

Navigation

Languages

Python Generator Demo

Snippet info

Language

Python

Visibility

public

Author

steinwaywhw

Created

2016-09-27T20:02:08Z

Updated

2016-09-27T20:02:08Z



def f(n): 
    x = n
    while True:
        yield x
        x = x+1
    
def take(xs, n):
    if n == 0:
        return []
    else:
        return [next(xs)] + take(xs, n-1)
    
print(take(f(2), 10))
INFO