I am tasked to merge the lists into a single one. For example:
all_lst = [[2, 7, 10], [0, 4, 6], [3, 11]]
>>> [0, 2, 3, 4, 6, 7, 10, 11]
I have defined:
def merge(left, right):
results = []
while left and right:
if left[0]< right[0]:
results.append( left[0])
left.remove( left[0])
else:
results.append( right[0])
right.remove (right[0])
results.extend(left)
results.extend(right)
return results
and
def merge_lists(all_lst):
for i in range( len(all_lst)):
A = merge(all_lst[i], all_lst[ i+1])
new = all_lst[i+2:]
B = merge( list(A), list(new))
return B
However I am given by IDLE:
Traceback (most recent call last):
File "<pyshell#162>", line 1, in <module>
print(merge_lists(all_lst))
File "<pyshell#161>", line 5, in merge_lists
B = merge( list(A), list(new))
File "<pyshell#110>", line 4, in merge
if left[0]< right[0]:
TypeError: unorderable types: int() < list()
I would really appreciate it if you could tell me what's wrong. Thanks~!