Created
November 22, 2012 00:11
-
-
Save jbochi/4128651 to your computer and use it in GitHub Desktop.
lazy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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