Skip to content

Instantly share code, notes, and snippets.

@preston-56
Created April 4, 2024 16:56
Show Gist options
  • Select an option

  • Save preston-56/f8c130aa9579969806859ecef2988bab to your computer and use it in GitHub Desktop.

Select an option

Save preston-56/f8c130aa9579969806859ecef2988bab to your computer and use it in GitHub Desktop.
# ([1,2,3,4,5,6,7],3) === [[1,2,3],[3,4,5],[6,7]]
# ([1,2,3,5,6,7],1) == [[1],[2],[3],[5],[6],[7]]
def split_list(lst,n):
result = []
for i in range(0, len(lst),n):
result.append(lst[i:i+n])
return result
# Test cases
print(split_list([1,2,3,4,5,6,7],3))
print(split_list([1,2,3,5,6,7],1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment