def every(arr, every_num): new_list = [] for i in range(0, len(arr), every_num): new_list.append(arr[i: i + every_num]) return new_list mylist = [1, 2, 3, 4, 5, 6, 7, 8, 9] result = every(mylist, 4) print(result)
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter