Skip to content

Instantly share code, notes, and snippets.

@jbochi
Created November 22, 2012 00:11
Show Gist options
  • Save jbochi/4128651 to your computer and use it in GitHub Desktop.
Save jbochi/4128651 to your computer and use it in GitHub Desktop.
lazy
def ifilter(funcao, seq):
for x in seq:
if funcao(x):
yield x
def take(seq, n):
i = 0
for x in seq:
if i < n:
yield x
i += 1
else:
break
def naturais():
i = 0
while True:
yield i
i += 1
def pares():
return ifilter(lambda x: x % 2 == 0, naturais())
print sum(take(pares(), 10))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment