Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class take_skip:
- def __init__(self, step, count):
- self.step = step
- self.count = count
- self.iterations = 0 # това е ключово да се създаде
- def __iter__(self):
- return self
- def __next__(self):
- if self.iterations == self.count:
- raise StopIteration
- result = self.iterations * self.step # получава се 0 * 2 = 0, 1 * 2 = 2, 2 * 2 = 4, 3 * 2 = 6, 4 * 2 = 8, 5 * 2 = 10
- self.iterations += 1 # итерацията се увеличава с 1 --> 0, 1, 2, 3, 4, 5
- return result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement