Skip to content

Instantly share code, notes, and snippets.

@gabrielfalcao
Created November 24, 2010 23:46
Show Gist options
  • Save gabrielfalcao/714649 to your computer and use it in GitHub Desktop.
Save gabrielfalcao/714649 to your computer and use it in GitHub Desktop.
paginates python iterables in chunks of lists
def paginator_from_hell(items, chunk=5):
"""
usage:
paginator_from_hell(["A","A","A","A","A","B","B","B","B","B",0,0,0,0,0,"D","D","D","D","D","E","E"]
returns:
[
["A","A","A","A","A"],
["B","B","B","B","B"],
[0,0,0,0,0],
["D","D","D","D","D"],
["E","E"],
]
"""
return filter(lambda x:x, [filter(lambda x:x, [data and data.pop(0) for x in range(chunk)]) for y in range(chunk)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment