Home > other >  The python tuple and list the STR mutual conversion problem.
The python tuple and list the STR mutual conversion problem.

Time:11-30

Ay1=[' start ', 'stop']
Ay2=[' bin1 ', 'bin3]
Ay3=[' 172.18.14.29]

There are three list,
Ay1 and ay2 membership,
Ay3 list of member number and ay1, ay2,

Want to make it contains array of tuple
[(' start ', 'bin1', '172.18.14.29'), (' stop ', 'bin3', '172.18.14.29)]


Is the ay3 and cartesian product (ay1, ay2),

Namely (ay1 [0], ay2 [0], ay3 [0]), (ay1 [1], ay [1], ay [0])...

 
Ay1=[' yes', 'no']
Ay2=[' bin1 ', 'bin3]
Ay3=[' 172.18.14.29]

If __name__=="__main__ ':
Com1=zip (ay1, ay2)
Com2=[]
For I in itertools. Product (com1, ay3) :
Print (' listis -- -- -- -- -- ", I)
Com2. Append (I)
Print com1
Print com2

So there is something wrong with the output
[((' yes', 'bin1'), '172.18.14.29'), ((' no ', 'bin3'), '172.18.14.29)]
A tuple within a () do not conform to the requirements of the I,
Just want to remove the tuple inside the parentheses, no success

Try another way,
 
Ay1=[' yes', 'no']
Ay2=[' bin1 ', 'bin3]
Ay3=[' 172.18.14.29]

If __name__=="__main__ ':
Com1=zip (ay1, ay2)
Com2=[]
For I in iter (com1) :
For p in the range (len (ay3) :
Add1=I + the tuple (ay3 [p])
Print (' zip_stat_bin_add is, add1)
Com2. Append (add1)
Print com1
Print com2

The tuple (ay3 [p]) split the list directly to each character content, and results also vary a lot,
[(' yes', 'bin1', '1', '7', '2', '. ', '1', '8', '. ', '1', '4', '. ', '2', '9'), (' no ', 'bin3', '1', '7', '2', '. ', '1', '8', '. ', '1', '4', '. ', '2', '9')]

Was not recruit,

CodePudding user response:

 
Ay1=[' yes', 'no']
Ay2=[' bin1 ', 'bin3]
Ay3=[' 172.18.14.29 ', '123.123.123]


If __name__=="__main__ ':
Print (' res is index. P y -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ')
Zip_stat_bin_ip=[]
Zip_stat_bin=zip (ay1, ay2)
Zip_ip=zip (ay3)
For I in iter (zip_stat_bin) :
For p in iter (tuple (zip_ip) :
Add1=I + p
Print (' zip_stat_bin_add is, add1)
Zip_stat_bin_ip. Append (add1)
Print (zip_stat_bin_ip, 'this is com1reslut')


Ah,, oneself are done,

CodePudding user response:

 ay1=[' yes', 'no'] 
Ay2=[' bin1 ', 'bin3]
Ay3=[' 172.18.14.29 ', '123.123.123]

If __name__=="__main__ ':
Z=[I + (j) for j in ay3 for I zip (ay1, ay2)] in
Print (z)

CodePudding user response:

Ay1=[' start ', 'stop']
Ay2=[' bin1 ', 'bin3]
Ay3=[' 172.18.14.29]
Com=[]
For I in zip (ay1, ay2) :
I +=a tuple (ay3)
Com. Append (I)
.
> Com
[(' start ', 'bin1', '172.18.14.29'), (' stop ', 'bin3', '172.18.14.29)]
Is this meaning?

CodePudding user response:

 ay1=[' yes', 'no'] 
Ay2=[' bin1 ', 'bin3]
Ay3=[' 172.18.14.29 ', '123.123.123]

If __name__=="__main__ ':
Z=[(* I, j) for j in ay3 for I zip (ay1, ay2)] in
Print (z)
  • Related