python - How to merge item in list -


i have problem list in python. when print "list" have results:

[1,2,3] [4,5,6] 

so have 2 lists in 1 variable guess. how can merge items 1 variable ?

try ,

>>> [[1, 2, 3], [4, 5, 6]] >>> result=[] >>> in a:     result+=i   >>> result [1, 2, 3, 4, 5, 6] >>> 

or

>>> [[1, 2, 3], [4, 5, 6]] >>> sum(a, []) 

output:

[1, 2, 3, 4, 5, 6] 

or

>>> a1 [1, 2, 3] >>> a2 [4, 5, 6] >>> [item item in itertools.chain(a1, a2)] 

output:

[1, 2, 3, 4, 5, 6] 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -