Skip to content
Advertisement

How to Remove nested list which is inside a nested list in python?

I want to remove all nested list inside the nested list. Which means

JavaScript

I want to remove the nested list in index 1,2,3,4… and make it a flat list. To make it clear the below is the separated values in the list.

JavaScript

I want it as

JavaScript

And are there any way to get input like above.

JavaScript

This was the snippet I used to get that x list.

Advertisement

Answer

With a helper recursive function for flattening nested sublists along with a list comprehension:

JavaScript

to get

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement