I have this problem E1). L is a list whose elements may be hidden. A hidden element is one that is stored inside one or more lists in the list L. Design a recursive function that displays all the "visible elements" of L
for example For L = [1,[2],[[3]],[4,5],6], the expected result is [1,2,3,4,5,6]. In this example the numbers 1 and 6 are visible and the elements 2, 3, 4 and 5 are hidden.
im learning recursion in python, i tried to find a solution for this problem but i was just able to do this:
l = [1,2,4,5,6]
def simple_vista(l):
if l==[]:
return 0
else:
if isinstance(l[0], list):
pass
else:
l[0] + simple_vista(l[1:])
print("los numeros a simple vista son: ", simple_vista(l))
The idea that i have to solve the problem:
My idea is to check if the l[0] is a iterable type item (a list) and if is it, ignore it and the same with the rest of elements of the list (l[1:]), if an element is not a iterable type item, save it and at the end, show that numbers.
Note: recursion means that im not able to use cicles for and while in order to answer the problem