Skip to content

Instantly share code, notes, and snippets.

@tejas-kr
Created September 16, 2024 10:15
Show Gist options
  • Save tejas-kr/1a846bb998e43116e24f7e54377fe2d5 to your computer and use it in GitHub Desktop.
Save tejas-kr/1a846bb998e43116e24f7e54377fe2d5 to your computer and use it in GitHub Desktop.
Flatten a nested list using recursion
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