Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Try writing your own iterator class that allows you
- # to specify the lengths of steps the iterator makes.
- # eg. when you call you step iterator class you specify the steps.
- class IterSteps:
- def __init__(self,data,step):
- self.index = 0
- self.data = data
- self.indexes = list(range(0,step,len(data)))
- self.step = step
- def __iter__(self):
- return self
- def __next__(self):
- if self.index > len(self.data) - 1:
- raise StopIteration
- self.index += self.step
- return self.data[self.index - self.step]
- def main():
- itstep = IterSteps("Pikachu",3)
- for thing in itstep:
- print(thing)
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement