28_iter.py 147 B

123456789101112
  1. a = [1, 2, 3]
  2. a = iter(a)
  3. total = 0
  4. while True:
  5. obj = next(a)
  6. if obj is StopIteration:
  7. break
  8. total += obj
  9. assert total == 6