Skip to content

Instantly share code, notes, and snippets.

@dgouldin
Created December 7, 2011 23:19
Show Gist options
  • Save dgouldin/1445242 to your computer and use it in GitHub Desktop.
Save dgouldin/1445242 to your computer and use it in GitHub Desktop.
Patination of an interable into a generator of page_size lists.
def paginate_iterable(iterable, page_size):
current_page = []
for item in iterable:
current_page.append(item)
if len(current_page) == page_size:
yield current_page
current_page = []
if len(current_page) > 0:
yield current_page
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment