Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python convert two dimensional list to one dimensional

# Python convert 2D into 1D array:

import itertools
x = [['foo'], ['bar', 'baz'], ['quux'], ("tup_1", "tup_2"), {1:"one", 2:"two"}]
print list(itertools.chain(*x))
print [element for sub in x for element in sub]

# Output:

['foo', 'bar', 'baz', 'quux', 'tup_1', 'tup_2', 1, 2]

Source by www.daniweb.com #
 
PREVIOUS NEXT
Tagged: #python #convert #dimensional #list #dimensional
ADD COMMENT
Topic
Name
5+7 =