Question: Python merge two sorted lists function . I can't figure out how to make it merge lists of uneven lengths or to put the left

Python merge two sorted lists function .

I can't figure out how to make it merge lists of uneven lengths or to put the left over numbers where they need to be.

This merge function takes two sorted lists and combines them into a new new list and returns that list

Code:

def merge(listA, listB):
listA =[5, 10, 15, 20]
listB =[3, 7, 12, 19 ]
merg = []
indA = 0
indB = 0
while indA < len(listA) and indB < len(listB):
if listB[indB] < listA[indA]:
merg.append(listB[indB])
indB = indB + 1
else:
merg.append(listA[indA])
indA = indA + 1
return merg
listA =[5, 10, 15, 20,14,23,34]
listB =[3, 7, 12, 19 ]
pear = merge(listA,listB)
print(pear)

end:

heres a better link

https://gist.github.com/anonymous/7d3aa8ea49133518e66a881d552c9a7b

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!