Created
May 21, 2014 14:36
-
-
Save marcellmars/a5dad641aa69b4aed111 to your computer and use it in GitHub Desktop.
list2chunks returns new list with chunks from the input list. chunks are having lenghts of chlen and with the last chunk being merged if shorter than chlen
This file contains 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 list2chunks(lst, chlen=10, chcount=0, chunks=[], tail = 0.5): | |
'''it returns new list with chunks from the input list. \ | |
chunks are having lenghts of chlen and with the last chunk \ | |
being merged if shorter than chlen''' | |
if len(lst) <= chlen + tail * chlen: | |
chunks.append(lst[chcount:]) | |
return chunks | |
chunk = lst[chcount:chcount+chlen] | |
chcount += chlen | |
chunks.append(chunk) | |
return list2chunks(lst[chcount:], chunks=chunks) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment