In this answer, we have share a python program to Flatten a list without using recursion with program output. Copy the below Python program and execute it to see the real time output.
1 2 3 | a=[[1,[[2]],[[[3]]]],[[4],5]] flatten=lambda l: sum(map(flatten,l),[]) if isinstance(l,list) else [l] print(flatten(a)) |
Program Output
1 | [1, 2, 3, 4, 5] |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.