# Split list into n chunks

Chunks a list into `n` smaller lists.

• Use `math.ceil()` and `len()` to get the size of each chunk.
• Use `list()` and `range()` to create a new list of size `n`.
• Use `map()` to map each element of the new list to a chunk the length of `size`.
• If the original list can't be split evenly, the final chunk will contain the remaining elements.
```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)))
)

chunk_into_n([1, 2, 3, 4, 5, 6, 7], 4) # [[1, 2], [3, 4], [5, 6], [7]]```

## More like this

• Python ·

### Split list into chunks

Chunks a list into smaller lists of a specified size.

• Python ·

### Bifurcate list based on function

Splits values into two groups, based on the result of the given filtering function.

• Python ·

### Bifurcate list based on values

Splits values into two groups, based on the result of the given `filter` list.

• Python ·

### N max elements

Returns the `n` maximum elements from the provided list.

Start typing a keyphrase to see matching snippets.