Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Simple Solution solution in Clear category for Split List by sawako.oono
def split_list(items: list) -> list:
split1 = []
split2 = []
if len(items)%2 == 0:
split1 = items[0:int(len(items)/2)]
split2 = items[int(len(items)/2):len(items)]
else:
split1 = items[0:int((len(items)+1)/2)]
split2 = items[int((len(items)+1)/2):len(items)]
ans = [split1,split2]
return ans
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, 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("Coding complete? Click 'Check' to earn cool rewards!")
May 20, 2021
Comments: