Created
April 4, 2024 16:56
-
-
Save preston-56/f8c130aa9579969806859ecef2988bab to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| # ([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