Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Short solution in Clear category for Split List by PistoleroAlan
from typing import Any, Iterable
from math import ceil
split_list=lambda items:[items[:ceil(len(items)/2)], items[ceil(len(items)/2):]]
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([])) == [[], []]
assert list(split_list([1])) == [[1], []]
print("The mission is done! Click 'Check Solution' to earn rewards!")
Aug. 26, 2023
Comments: