Last active
August 29, 2015 14:22
-
-
Save sabriedd/83ca2d172cdeb54a02a2 to your computer and use it in GitHub Desktop.
Split a list in a given number of sub-list equitably distributed.
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 split_list(source_list, number_of_chunks): | |
chunks = [] | |
start = 0 | |
step = len(source_list) / number_of_chunks | |
rest = len(source_list) % number_of_chunks | |
end = start + step | |
for i in range(0,number_of_chunks): | |
chunks.append(source_list[start:end]) | |
start = end | |
end = start + step | |
for i in range(0, rest) : | |
chunks[i].append(source_list[-(i+1)]) | |
return chunks |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment