Convert Nested List To Flat List

 

Code


Suppose you have a list like :

[[1], [2,3], [4, [5, 6]], [7], [8], [9], [10]]


Now if I want to make it a flat list like :

[1,2,3,4,5,6,7,8,9]


How can we do that?  😕 

Don't worry dear, there are many ways to do so. You are going to take help one builtin lib of python 😍


# Example


from functools import reduce

>>> l = [[1], [2,3], [4, 5, 6], [7], [8], [9], [10]]

>>> flat_list = reduce(lambda x, y: x+y, l)

>>> flat_list

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]


Enjoy Edge-cutting Technology 😉



Get Help

Comments

Popular posts from this blog

How To Create .ENV File in Python

Create a Large file for Test Data Processing using Python

How to solve the Liner Equation using Python