Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Speedy category for Split List by PelmenFloopov
from typing import Any, Iterable
def split_list(items: list[Any]) -> Iterable[list[Any]]:
result: list = []
midleIndex = len(items) // 2 + 1 if len(items) % 2 != 0 else len(items) // 2
result.append(items[:midleIndex])
result.append(items[midleIndex:])
return result
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!")
Feb. 12, 2024
Comments: