Last active
January 31, 2018 16:00
-
-
Save ZoltonMD/2b385bb0dab9d81542fa529568cdaa5e to your computer and use it in GitHub Desktop.
Split list into chunks
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 chunk_into_n_parts(list, n): | |
"""Split list into n chunks | |
Args: | |
list (list): splittable list | |
n (int): amount of chunks | |
Returns: | |
(list): list of n chunks | |
""" | |
return [list[i::n] for i in xrange(n)] | |
def chunk_into_parts_of_n(list, n): | |
""" Split lits into chunks of n" | |
Args: | |
list (list): splittable list | |
n (int): number of elements in chunk | |
Returns: | |
(list): list of chunks of n | |
""" | |
return [list[i:i+n] for i in range(0, len(list), n)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment