Created
December 7, 2011 23:19
-
-
Save dgouldin/1445242 to your computer and use it in GitHub Desktop.
Patination of an interable into a generator of page_size lists.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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