Define a function
split_listthat takes in a list of numbers and a numberaand splits it into two sublists:list1that contains numbers smaller than or equal toa, and another list,list2containing numbers greater than a.list1andlist2must be returned as elements of a tuple.
My code:
def split_list(lst, a):
list1 = []
list2 = []
for i in lst:
if i <= a:
list1.append(i)
lst.remove(i)
elif i > a:
list2.append(i)
lst.remove(i)
return (list1, list2)
Test code:
split_list([1, 10, 4, 9, 7, 2, 5, 8, 3, 4, 9, 6, 2], 5)
should give: ([1, 4, 2, 5, 3, 4, 2], [10, 9, 7, 8, 9, 6])
But I got ([1, 4, 5, 3, 2], [7, 9]) instead. Whats wrong with my code?