Here's a Python function that can divide a list into chunks of a specified size:
main.py273 chars8 lines
This function uses list comprehension to split the list into chunks of size 'chunk_size' and returns a list of those chunks. Here's an example of how to use the function:
main.py164 chars8 lines
In this example, we have a list my_list
and we want to split it into smaller lists of size 3, so we call the chunk_list
function with my_list
and chunk_size
as arguments, and it returns a list of lists containing the desired chunks.
gistlibby LogSnag