Advent of Python 2026Starts 1 Dec →

    Day 11Chunk a List

    Easylistsslicing

    Write chunk(items, size) that splits items into lists of size items each, in order. The last chunk may be shorter.

    chunk([1, 2, 3, 4, 5], 2) returns [[1, 2], [3, 4], [5]].

    Examples

    Example 1
    >>> chunk([1, 2, 3, 4, 5], 2)
    [[1, 2], [3, 4], [5]]
    Example 2
    >>> chunk(["a", "b", "c"], 3)
    [["a", "b", "c"]]

    Good to know

    • size is at least 1. An empty list gives [].

    Run examples checks the 2 examples above. Submit runs all 6 tests, including hidden edge cases, and marks the challenge solved.

    solution.py
    Loading Python…

    Test results show up here

    Write chunk in the editor, then run the examples. Use print() freely: its output is shown for each test.