Skip to content

Instantly share code, notes, and snippets.

@att288
Last active May 5, 2019 21:19
Show Gist options
  • Save att288/4a264cc2121cedc5bfd64aa9aec67673 to your computer and use it in GitHub Desktop.
Save att288/4a264cc2121cedc5bfd64aa9aec67673 to your computer and use it in GitHub Desktop.
generator_send.py
def multiplier(n):
step = None
result = 1
for i in range(1, n+1):
if step is None:
step = 1
result *= (i*step)
print(f"i:{i}, step={step}")
step = yield result
my_generator = multiplier(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment