I'm trying to write a function with recursion that will return True if the element is in the nested list or False of it isn't. So far my code works only for certain elements:
def inthere(ls, s):
if s in ls:
return True
else:
for thing in ls:
if isinstance(thing, list):
return inthere(thing,s)
When I run:
A=[[2,4],[6,[[[8],10]],12],14,16]
print(inthere(A,12)) #Should return True, but does not.
print(inthere(A,2)) #Returns True, as it should.
I'm definitely missing something here, I can't seem to tell, I appreciate all the help!