Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python denest list of anything

l = [1,"bob",[[4,3],[2,1]], ["a","b","c"], np.asarray([1,2,3])]
flatten = lambda *n: (e for a in n for e in (flatten(*a) if isinstance(a, (tuple, list)) else (a,)))
list(flatten(l))
>>> [1, 'bob', 4, 3, 2, 1, 'a', 'b', 'c', array([1, 2, 3])]
Comment

PREVIOUS NEXT
Code Example
Python :: when to use static method in python 
Python :: An error occurred while connecting: 10049: The requested address is not valid in its context.. scrapy splash 
Python :: python yield async await thread function 
Python :: gensim loop keyed vector 
Python :: panda3d intervals 
Python :: python static typing 
Python :: python print list of keywords 
Python :: change tag name using beautifulsoup python 
Python :: Find From Table Django 
Python :: 3x4 matrix 
Python :: is tkinter built into python 
Python :: dictionart 
Python :: Boolean comparison w/out if statements 
Python :: python recognize lower and upper case user input 
Python :: python file operation 
Python :: Matrix Transpose using Nested List Comprehension 
Python :: python map and filter 
Python :: how do i re-restablish the third reich 
Python :: django multi column index 
Python :: latex maths to python parser 
Python :: File "demo_indentation_test.py", line 2 print("Five is greater than two!") ^ IndentationError: expected an indented block 
Python :: i want to get only first record of each user in pandas 
Python :: 1 min candle resampling pandas 
Python :: numpy index array all except 
Python :: MEDIANA EN PANDAS 
Python :: Python Using Global and Local variables in the same code 
Python :: python @property decorator 
Python :: Errors that you will get in the Time class in Python DateTime 
Python :: iterate over the dataset and compute the mean vector. 
Python :: poisson random data 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =