Advertisement
horozov86

take_skip

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