Guest User

Untitled

a guest
Jan 22nd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. class ListChunk:
  2. def __init__(self, items, chunksize):
  3. self.items = items
  4. self.chunksize = chunksize
  5. self.ii = 0
  6. def __iter__(self):
  7. return self
  8. def next(self):
  9. if self.ii >= len(self.items):
  10. raise StopIteration
  11. tmp = self.items[self.ii:self.ii + self.chunksize]
  12. self.ii = self.ii + self.chunksize
  13. return tmp
  14.  
  15. items = ListChunk([1,2,3,4,5,5,6,7,8], 2)
  16. for slice in items:
  17. print slice
Add Comment
Please, Sign In to add comment