Skip to content

Instantly share code, notes, and snippets.

@moreati
Last active August 1, 2022 22:56
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 moreati/73cf6312b5bdab8379695ba0d72e092c to your computer and use it in GitHub Desktop.
Save moreati/73cf6312b5bdab8379695ba0d72e092c to your computer and use it in GitHub Desktop.
def corange(end):
i = 0
while i < end:
v = yield i
if isinstance(v, int):
end = v
i += 1
for i in (r := corange(10)):
print(i)
if i == 2:
i = r.send(4)
print(i)
@moreati
Copy link
Author

moreati commented Aug 1, 2022

$ python3 coroutine_walrus.py
1
2
3

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