Home > other >  The consolidation of Python list
The consolidation of Python list

Time:11-29

A1=[' store_no1 ', 'store_no2]
A2=[' m3_no1 ', 'm3_no2]

Have list of a1 and a2, what command can be merged into a3 list look like?

A3=[[' store_no1 ', 'm3_no1], [' store_no2', 'm3_no2]]

CodePudding user response:

A3=(a1, a2)

CodePudding user response:

 a1=[' store_no1 ', 'store_no2] 
A2=[' m3_no1 ', 'm3_no2]

Print (list (map (list, zip (a1, a2))))

# [[' store_no1 ', 'm3_no1], [' store_no2', 'm3_no2]]

CodePudding user response:

 
A1=[' store_no1 ', 'store_no2]
A2=[' m3_no1 ', 'm3_no2]
A3=[]
For x, y in the zip (a1, a2) :
A3. Append ((x, y))
Print (a3)

CodePudding user response:

reference 1st floor mklpo147 response:
a3=(a1, a2)


You this is the right formula, the result is like this:
[[' store_no1 ', 'store_no2], [' m3_no1', 'm3_no2]]

CodePudding user response:

The
reference 5 floor goto527 response:
Quote: 1/f, reference mklpo147 response:
a3=(a1, a2)


You this is the right formula, the result is like this:
[[' store_no1 ', 'store_no2], [' m3_no1', 'm3_no2]]


[[[0] a1, a2, a3=[0]], [1] [a1], a2 [1]]

CodePudding user response:

(a1, a2, a3=list (zip))
  • Related