Search
 
SCRIPT & CODE EXAMPLE
 

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]
Comment

PREVIOUS NEXT
Code Example
Python :: remove all elements from list python by value 
Python :: python add 1 to 100 
Python :: appending objects to a list contained in a dictionary python 
Python :: python set match two list 
Python :: torch root mean square 
Python :: open file with python 
Python :: strip whitespace python 
Python :: flat numpy array 
Python :: python random number generator no duplicates 
Python :: big comments python 
Python :: Get a list of categories of categorical variable (Python Pandas) 
Python :: flask api with parameter 
Python :: jupyter matplotlib 
Python :: np.arrange 
Python :: python program to find the sum of fibonacci series 
Python :: python To find the sum of all the elements in a list. 
Python :: username python system 
Python :: .lift tkinter 
Python :: download images off unsplash python 
Python :: table in sqlite python 
Python :: python multithreading 
Python :: discord.py permissions 
Python :: handwritten digits data set 
Python :: python decorator 
Python :: Your WhiteNoise configuration is incompatible with WhiteNoise v4.0 
Python :: how to check a string is empty in python 
Python :: separate words in a text to make a list python 
Python :: appending items to a tuple python 
Python :: python dict access 
Python :: join python documentation 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =