Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Split List by vlad.bezden
"""Split List
https://py.checkio.org/en/mission/split-list/
You have to split a given array into two arrays.
If it has an odd amount of elements,
then the first array should have more elements.
If it has no elements, then two empty arrays should be returned.
example
Input: Array.
Output: Array or two arrays.
Example:
split_list([1, 2, 3, 4, 5, 6]) == [[1, 2, 3], [4, 5, 6]]
split_list([1, 2, 3]) == [[1, 2], [3]]
"""
def split_list(items: list) -> list:
i = (len(items) + 1) // 2
return [items[:i], items[i:]]
if __name__ == "__main__":
assert split_list([1, 2, 3, 4, 5, 6]) == [[1, 2, 3], [4, 5, 6]]
assert split_list([1, 2, 3]) == [[1, 2], [3]]
assert split_list([1, 2, 3, 4, 5]) == [[1, 2, 3], [4, 5]]
assert split_list([1]) == [[1], []]
assert split_list([]) == [[], []]
print("PASSED!!!")
May 17, 2020