t233.py 350 B

123456789101112131415161718192021
  1. # multiple instances of generator at the same time
  2. def genmaker(a, b):
  3. z = a*b
  4. def gen(y):
  5. for i in range(4):
  6. yield i,a,b,y,z
  7. return gen(a*a*b*b)
  8. g1 = genmaker(3, 4)
  9. g2 = genmaker(4, 5)
  10. print g1.next()
  11. print g2.next()
  12. print g1.next()
  13. print g2.next()
  14. print g1.next()
  15. print g2.next()
  16. print g1.next()
  17. print g2.next()