Currently, I'm working on a problem. I am given a list, whose elements may contain other lists, lists of lists, or integers. For example, I may receive:
[[[[], 1, []], 2, [[], 3, []]], 4, [[[], 5, []], 6, [[], 7, [[], 9, []]]]]
My goal is to parse the array, and append only the integers to a new list. Here is what I have done so far:
def fun(a):
if a == []:
return None
elif type(a) == int:
print("Found a digit: ", a)
return a
for i in a:
fun(i)
Currently, this function recursively goes through the list and successfully finds each integer; now, I am having an issue with appending those integers to a new list, and returning that list at the very end. The output should be like this:
[1,2,3,4,5,6,7,9]
Any pointers?