I need to make a function which receive 2 nested lists, and checks if they are the same with recursion. The main problem is that I am not allowed to use the ==
operator on the lists, change the original lists, or use loops. The function returns True if the lists are the same, and False if not.
For example, The function will return True for the lists
lst_1 = [[1,2,3], [4,5,6]] lst_2 = [[1,2,3], [4,5,6]]
and returns False for the following:
lst_1 = [[1,2,3], [4,5,6]] lst_2 = [[1,2,3], [4,5]]
def func(l1, l2):
if len(l1) != len(l2):
return False
if len(l1[0]) == 0 and len(l2[0]) == 0:
return True
if len(l1[-1]) == 0 and len(l2[-1]) == 0:
del l1[-1]
del l2[-1]
if l1[-1][-1] != l2[-1][-1]:
return False
l1[-1].pop(-1)
l2[-1].pop(-1)
return func(l1, l2)
I have tried to do this with pop, but apparently it changes the original list.