I'm trying to solve the following:
Write a recursive function:
isEqual(list1, list2)
that returns a Boolean value indicating whether the two lists are equal without directly comparinglist1 == list2
. You may only compare the lengths of the lists and test whether individual list elements are equal. [hint: two lists are "equal" iff they are the same length and every corresponding element is the same]
This is what is have so far, but I am stuck. Any help out there?
def isEqual(list1, list2):
if len(list1) and len(list2) < 1:
return True
elif len(list1) == len(list2) and list1[-1] == list2[-1]:
isEqual(list1[:-1], list2[:-1]) + isEqual
return True
else:
return False