Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Split List by DianaAlcocer
from typing import Any, Iterable
def split_list(items: list[Any]) -> Iterable[list[Any]]:
middle = (len(items)+1) //2
return items[:middle], items[middle:]
print("Example:")
print(list(split_list([1, 2, 3, 4, 5, 6])))
assert list(split_list([1, 2, 3, 4, 5, 6])) == [[1, 2, 3], [4, 5, 6]]
assert list(split_list([1, 2, 3])) == [[1, 2], [3]]
assert list(split_list(["banana", "apple", "orange", "cherry", "watermelon"])) == [
["banana", "apple", "orange"],
["cherry", "watermelon"],
]
assert list(split_list([1])) == [[1], []]
assert list(split_list([])) == [[], []]
print("The mission is done! Click 'Check Solution' to earn rewards!")
Jan. 5, 2026
Comments: