Here's an example of a function that splits a list into chunks of a specified size using slicing:
main.py274 chars13 lines
This function takes in two arguments: the list to split (lst
) and the size of each chunk (size
). It then uses list comprehension and slicing to create a list of chunks.
Here's an example of using this function:
main.py107 chars6 lines
Output:
main.py34 chars2 lines
gistlibby LogSnag