Created
March 2, 2019 20:29
-
-
Save mikeplavsky/68852c9b41ae617c149311b7b1186be8 to your computer and use it in GitHub Desktop.
This file contains 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 accumulate(): | |
res = 0 | |
while True: | |
t = yield | |
if t == None: | |
return res | |
res += t | |
def tallies(ts): | |
while True: | |
t = yield from accumulate() | |
ts.append(t) | |
def main(): | |
ts = [] | |
acc = tallies(ts) | |
acc.send(None) | |
for i in range(4): | |
acc.send(i) | |
acc.send(None) | |
for i in range(5): | |
acc.send(i) | |
acc.send(None) | |
print(ts) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What will it print?