Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Split List by ivantukala
def split_list(items: list) -> list:
s=int(len(items)/2+0.5)
return [items[0:s]] + [items[s:]]
if __name__ == '__main__':
print("Example:")
#print(split_list([1, 2, 3, 4, 5, 6]))
# These "asserts" are used for self-checking and not for an auto-testing
assert split_list([1, 2, 3, 4, 5]) == [[1, 2, 3], [4, 5]],1
assert split_list([1, 2, 3, 4, 5, 6]) == [[1, 2, 3], [4, 5, 6]],2
assert split_list([1, 2, 3]) == [[1, 2], [3]],3
assert split_list([1]) == [[1], []],4
assert split_list([]) == [[], []],5
print("Coding complete? Click 'Check' to earn cool rewards!")
June 25, 2020