-2
I need to write a recursive function that takes 2 lists and returns a new list by subtracting the elements from the first ones, for example:
>>> subtrai([2, 3, 4, 5], [2, 3])
[4, 5]
I know I need to know if an element from the 1st list belongs to the 2nd: in case it belongs this element cannot be part of the result, otherwise it belongs.
The problem is that I cannot use the remove function()...
Right now I have the following code
elem = []
if elem in l1 and l2:
return list(l1-l2)
else:
return l1
This code returns me only list 1, I can’t figure out what I’m doing wrong
I thank you in advance for your help
Yes, this implementation would be the solution. However, I cannot use the remove() function. That’s why I can’t solve the problem.
– rguest
@rguest can use del?
– britodfbr
Since del does the same function that removes it (if I am not mistaken, if you are please clarify me), I guess I could not have used it either. So I chose to use remove anyway.
– rguest