Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # chunk_into_n.py
- from math import ceil
- def chunk_into_n(lst, n):
- size = ceil(len(lst) / n)
- return list(
- map(lambda x: lst[x * size:x * size + size],
- list(range(n)))
- )
- ttt = [1, 2, 3, 4, 5, 6, 7]
- print( chunk_into_n(ttt, 4) ) # [[1, 2], [3, 4], [5, 6], [7]]
- print( chunk_into_n(ttt, 3) ) # [[1, 2, 3], [4, 5, 6], [7]]
Add Comment
Please, Sign In to add comment