Skip to content

Instantly share code, notes, and snippets.

@ZoltonMD
Last active January 31, 2018 16:00
Show Gist options
  • Save ZoltonMD/2b385bb0dab9d81542fa529568cdaa5e to your computer and use it in GitHub Desktop.
Save ZoltonMD/2b385bb0dab9d81542fa529568cdaa5e to your computer and use it in GitHub Desktop.
Split list into chunks
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