Python Tricks #15 - Convert list of list into single list

Words
0
Reading
0 min
Listen
Play
7y
# import the itertools 
import itertools 
  
# Declaring the list geek 
geek = [[1, 2], [3, 4], [5, 6]] 
  
# chain.from_iterable() function returns the elements of nested list 
# and iterate from first list of iterable till the last 
# end of the list 
  
lst = list(itertools.chain.from_iterable(geek)) 
print(lst)

# Output: 
# [1, 2, 3, 4, 5, 6]

Python Tricks #15 - Convert list of list into single list | Ecency