Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Im trying to write a python function that will compare 2 lists and recursively s

ID: 3675990 • Letter: I

Question

Im trying to write a python function that will compare 2 lists and recursively show if they are equal or not, but recursion is really confusing for me at the moment. Any help would be appreciated. I am to do this without without directly comparing the lists (ex. lst1 ==lst2). I can only compare the length of both the lists and I can test whetherindividual list elements are the same. Also, I can only use the built in len function, and the only other function call I can make is the recursive call itself. Here is what I have so far:

Example output:

>>> compare(['ispython',2,3],['ispython',2,3])

True

The error code Im getting tell me "list index out of range". Any help would be really valuable!

Explanation / Answer

You dont need to compare each and every element of the list you can try to use the follwing method to compare the whole list in a single run ;-

For example :-

This program will print 1 when the list are equal and -1 if not.