How to code this in python NOTE YOUCANNOT USE THE SORT FUNCTION THAT IS DEFINED
ID: 3641083 • Letter: H
Question
How to code this in pythonNOTE YOUCANNOT USE THE SORT FUNCTION THAT IS DEFINED IN LIST Write a function called combine_two_sorted_lists that takes in as input two lists(both the list are sorted) and combines them together to create a newlist. This new list is sorted as well and is returned. Forexample.List1=[10,20,30,40,50]List2=[15,25,35,45,55]
:List3=[10,15,20,30,35,40,45,50,55]
Explanation / Answer
you have to indent the code correctly so it will run Hope this helps you. def combList(lis1,lis2): lis3 = lis1 +lis2 isSorted = "true" i = 0 ii = 1 #O(n^2) this is not ideal while(1): print "run" if(lis3[i]>lis3[ii]): temp = lis3[i] lis3[i] = lis3[ii] lis3[ii] = temp ii +=1 if(ii==len(lis3) ): i +=1 ii = i+1 if(i==len(lis3)-2): break return lis3
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.