Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python expand nested list

# credit to the Stack Overflow user in the source link
"""Note: using 'chain' is about 20% faster than nested looping"""
from itertools import chain

nested_list = [[1,2,3], [4,5,6], [7], [8,9]]
expanded_list = list(chain(*nested_list))
expanded_list
>>> [1,2,3,4,5,6,7,8,9]
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #expand #nested #list
ADD COMMENT
Topic
Name
9+5 =