Skip to content

Instantly share code, notes, and snippets.

@mhrivnak
Last active December 16, 2015 10:49
Show Gist options
  • Save mhrivnak/5423112 to your computer and use it in GitHub Desktop.
Save mhrivnak/5423112 to your computer and use it in GitHub Desktop.
import itertools
def paginate(iterable, page_size):
i = 0
while True:
page = list(itertools.islice(iterable, i, i+page_size))
if not page:
return
i = i + page_size
yield page
@bowlofeggs
Copy link

I think it should say "while True or False" just for kicks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment