Skip to content

Instantly share code, notes, and snippets.

@mikeplavsky
Created March 2, 2019 20:29
Show Gist options
  • Save mikeplavsky/68852c9b41ae617c149311b7b1186be8 to your computer and use it in GitHub Desktop.
Save mikeplavsky/68852c9b41ae617c149311b7b1186be8 to your computer and use it in GitHub Desktop.
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)
@mikeplavsky
Copy link
Author

What will it print?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment