Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Math.ceil solution in Clear category for Split List by Striga
import math
def split_list(items: list) -> list:
half = math.ceil(len(items)/2)
return [items[:half], items[half:]]
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([]) == [[], []]
Oct. 23, 2020
Comments: