I need to unpack a nested list of this type:
lst = [5,2,3,[4,5, (6,7, [9])]]
to this:
[5, 2, 3, 4, 5, 6, 7, 9]
What I did:
def unpack_seq(sequence: List[Any]) -> List[Any]:
final_lst = []
for el in sequence:
if isinstance(el, list) or isinstance(el, tuple):
res = final_lst.append(unpack_seq(el))
else:
res = final_lst.append(el)
return res
result = unpack_seq([1,2,3,[4,5, (6,7, [9])]])
print(result)
And I get --> NONE
What's wrong with my code?
Please, don't advise using Flatten, I am not supposed to use it and want to understand what I did wrong here. I also used a function from GeekforGeeks, but it doesn't work as needed.
Thank you!