Skip to content

Instantly share code, notes, and snippets.

@cocodrips
Created April 9, 2019 06:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cocodrips/72da9d604fce88cbd43f13fcd5bce3b6 to your computer and use it in GitHub Desktop.
Save cocodrips/72da9d604fce88cbd43f13fcd5bce3b6 to your computer and use it in GitHub Desktop.
Pythonのasyncio
def averager():
total = 0
count = 0
average = 0
while True:
term = yield average
total += term
count += 1
average = total / count
# avg = averager()
# next(avg)
# Out[20]: 0
# avg.send(3)
# Out[21]: 3.0
# avg.send(6)
# Out[22]: 4.5
# avg.send(10)
# Out[23]: 6.333333333333333
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment