Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from functools import partial
- from itertools import islice
- def paginate(iterable, page_size):
- get_pages = partial(islice, iter(iterable), page_size)
- while data := list(get_pages()):
- yield data
- pages = range(10) # Iterable
- # paginate works with generators, iterators and
- # iterables. Ordinary lists are also iterable.
- for pages in paginate(pages, 3):
- print(pages)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement