Write a function that takes in two sorted lists and outputs a sorted list that is their union
Could anyone help me to improve this code and make it more user-friendly? We are not supposed to use any built-in Python functions, but rather develop our own efficient algorithms.
def answer(list1, list2):
len1 = len(list1)
len2 = len(list2)
final_list = []
j = 0
k = 0
for i in range(len1+len2):
if k == len1:
final_list.append(list2[j])
j += 1
continue
if j == len2:
final_list.append(list1[k])
k += 1
continue
if list1[k] < list2[j]:
final_list.append(list1[k])
k += 1
else:
final_list.append(list2[j])
j += 1
return final_list
print answer([1, 2 , 17, 18, 100], [3, 3, 4, 5, 15, 19, 20, 101])