Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class IteratorWithoutZeros:
- def __init__(self, my_list, BEZ_ZER):
- self.list = my_list
- self.max = len(self.list)
- self.actual_position = 0
- self.BEZ_ZER = BEZ_ZER
- def __next__(self):
- if(self.BEZ_ZER):
- self.actual_position = self.actual_position + 1
- while self.list[self.actual_position] == 0:
- self.actual_position = self.actual_position + 1
- if self.actual_position == self.max:
- raise StopIteration
- return self.list[self.actual_position]
- else:
- self.actual_position = self.actual_position + 1
- if self.actual_position == self.max:
- raise StopIteration
- return self.list[self.actual_position]
- def __iter__(self):
- return self
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement