python how to unnest a nested list

Solutions on MaxInterview for python how to unnest a nested list by the best coders in the world

showing results for - "python how to unnest a nested list"
Roberto
04 Mar 2016
1# Basic syntax:
2unnested_list = list(chain(*nested_list))
3# Where chain comes from the itertools package and is useful for 
4#	unnesting any iterables
5
6# Example usage:
7from itertools import chain
8nested_list = [[1,2], [3,4]]
9my_unnested_list = list(chain(*nested_list))
10print(my_unnested_list)
11--> [1, 2, 3, 4]