daily pastebin goal
0%
SHARE
TWEET

Untitled

a guest Feb 20th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #can't change the body of this function
  2. def positive_integers_generator():
  3.     n = 1
  4.     while True:
  5.         x = yield n
  6.         if x is not None:
  7.             n = x
  8.         else:
  9.             n += 1
  10.  
  11. def change_generator(generator, n):
  12.   for i in generator():
  13.     if i%2 == 0:
  14.       yield(i)
  15.  
  16. g = positive_integers_generator()
  17.  
  18. # should print 1, 2, 4
  19. for _ in range(5):
  20.   n = next(g)
  21.   print(n)
  22.   change_generator(g, n)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top