Convert Nested List To Normal List Using List Comprehension In Python
How can I do the following in Python? a = [2,[33,4],[2,3,4,6]] li = [ i for i in a if isinstance(i,int) else j in i ] how do i convert list a into a = [2,33,4,2,3,4,6] I am able t
Solution 1:
You can use:
In [20]: [k for e in a for k in (e if isinstance(e, list) else [e])]
...:
Out[20]: [2, 33, 4, 2, 3, 4, 6]
Post a Comment for "Convert Nested List To Normal List Using List Comprehension In Python"