Created
November 24, 2010 23:46
-
-
Save gabrielfalcao/714649 to your computer and use it in GitHub Desktop.
paginates python iterables in chunks of 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 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