itertools.py 316 B

12345678910111213
  1. def zip_longest(a, b):
  2. a = iter(a)
  3. b = iter(b)
  4. while True:
  5. ai = next(a)
  6. bi = next(b)
  7. if ai is StopIteration and bi is StopIteration:
  8. break
  9. if ai is StopIteration:
  10. ai = None
  11. if bi is StopIteration:
  12. bi = None
  13. yield ai, bi