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
Post a Comment