Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. class IteratorWithoutZeros:
  2. def __init__(self, my_list, BEZ_ZER):
  3. self.list = my_list
  4. self.max = len(self.list)
  5. self.actual_position = 0
  6. self.BEZ_ZER = BEZ_ZER
  7.  
  8. def __next__(self):
  9. if(self.BEZ_ZER):
  10. self.actual_position = self.actual_position + 1
  11. while self.list[self.actual_position] == 0:
  12. self.actual_position = self.actual_position + 1
  13. if self.actual_position == self.max:
  14. raise StopIteration
  15. return self.list[self.actual_position]
  16. else:
  17. self.actual_position = self.actual_position + 1
  18. if self.actual_position == self.max:
  19. raise StopIteration
  20. return self.list[self.actual_position]
  21.  
  22. def __iter__(self):
  23. return self
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement