简体   繁体   中英

How can I complete match between arrays in arrays by using enumerate?

I have 2 array,

x_test=[(2 1 3 2 5 1),(2 1 3 4 1 2).........] # len(x_test)=172
y_test=[2,1,3,4,5,1,3,5.....................] # len(y_test)=172

How can I match them by index like (2 1 3 2 5 1) 2 ; (2 1 3 4 1 2) 1 .

print(list(enumerate(x_test,y_test)))

error:

'list' object cannot be interpreted as an integer
print(list(enumerate(x_test,y_test)))
print(list(enumerate(x_test,y_test)))

error:

TypeError                                 Traceback (most recent call last)
<ipython-input-48-491946acd941> in <module>
----> 1 print(list(enumerate(x_test,y_test)))

TypeError: 'list' object cannot be interpreted as an integer

You should use zip :

x_test=[(2,1,3,2,5,1),(2,1,3,4,1,2)]
y_test=[1,2]

for a, b in zip(x_test, y_test):
    print (a,b)

#(2, 1, 3, 2, 5, 1) 1
#(2, 1, 3, 4, 1, 2) 2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM