I'm trying to find if an number is in the given list but can't figure it out.
I figured out how to do this with just a list(not nested):
def find(lst, number):
if len(lst) == 0: #base case
return False
else:
return number in lst
But the problem is with a nested list the above code won't work
What I have so far:
def find(lst, number):
if len(lst) == 0:
return False
else:
for i in lst:
if isinstance(i, list):
for item in i:
if item == number:
return True
elif i == number:
return True
else:
continue
# Nested List (What it should output).
>>> find([1, [3, [4 , [7, 8]], 9]], 8)
True