ropering / Study

0 stars 0 forks source link

[Python] chunk #25

Open ropering opened 2 years ago

ropering commented 2 years ago
from math import ceil

def chunk(lst, size):
    return list(
        map(lambda x: lst[x * size:x * size + size],
            list(range(0, ceil(len(lst) / size)))))

chunk([1,2,3,4,5],2) # [[1,2],[3,4],5]