Created
September 16, 2024 10:15
-
-
Save tejas-kr/1a846bb998e43116e24f7e54377fe2d5 to your computer and use it in GitHub Desktop.
Flatten a nested list using recursion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
li = ["Ram", 12, [23, 56, "vinod"], [[12, "you"], 1], [["mnb"], | |
["kjhdsf", 123, 0.8876], [[98, 12, 34], [2345, 8987643]]]] | |
lo = [] | |
def flatten_list(li): | |
for i in li: | |
if isinstance(i, list): | |
flatten_list(i) | |
else: | |
lo.append(i) | |
flatten_list(li) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment