Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started