Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Simple Python on Recursion: 2. Write a function compare(list1, list2) that takes as inputs two lists of numbers, list1 andlist2, and that uses recursion to
Simple Python on Recursion:
2. Write a function compare(list1, list2) that takes as inputs two lists of numbers, list1 andlist2, and that uses recursion to compute and return the number of values in list1 that are larger than their corresponding value in list2. In other words, the function should comparelist1[0] with list2[0],list101] with list2[1],list1[2] with list2[2], etc, and it should return the number of positions at which the value from list1 is larger than the value from list2. For example >compareC[S, 3, 7, 9], [2, 4, 7, 8]) The above call returns 2, because - in position 0, 5> 2 - in position 1, 3 8 Thus, there are two positions (0 and 3) at which the value from list1 is larger than the value from list2 Note that it is possible for the two lists to have different lengths, in which case the function should only compare the positions at which the two lists both have values >compare([4, 2, 3, 7], [1, 5]) #4>1; 2 >> compa reCE4 , 2, 3], [1, 5, 0, 8]) # 4 > 1; 2 0; can't comp compareC[5, 3], O) comparec], [5, 3, 7]) This function is somewhat similar to the mylen function from lecture, but it needs to deal with lists instead of strings, and it needs to process two lists at the same time. You can find a modified version of mylen that handles both strings and lists hereStep 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