I just started learning python and there are some recursion questions that I can't seem to figure out. The most annoying one is this:
I need to build a function ind(e,L) where e is an int and L is a list.
By entering e if it is in the list the output needs to be its index
For example:
ind(42,[0,14,52,42,15]) -> 3
This is the code I wrote this far but the index I get is always 0. Can someone please explain to me what I am doing wrong?
def location(e,L):
if L == []:
return False
elif e == L[0]:
A = L[:-1].index(e)
return A
else:
return location(e,L[1:])
print(location(14,[1,2,14,1]))
thanks :)