Dec-22-2018, 10:39 PM
I have to do a RECURSIVE FUNCTION, comparing two lists and returning the elements that they don't have in common.
This is what I have so far:
This is what I have so far:
def compare(list1, list2): if list2[0] in list1: list1.remove(list2[0]) return compare(list1[1:], list2[1:]) return list1 #Example >>>>compare([2, 3, 4, 5], [2, 3]) [4, 5]I can compare if the first element of the list (list[0]) is the same but I am having trouble on how to compare the elements if they are not in the first position...I've tried many options but I'm a begginer in programming and don't really know how to do it. It must be a RECURSIVE FUNCTION, I can't use FOR or WHILE. And is there any way that I can do it without using remove()? Thank you so much