from math import ceil def batch(lst, size): return list( map(lambda x: lst[x * size:x * size + size], list(range(0, ceil(len(lst) / size))))) batch([1, 2, 3, 4, 5], 2) # [[1,2],[3,4],5]