[英]How can I complete match between arrays in arrays by using enumerate?
我有两个数组
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
我如何通过(2 1 3 2 5 1) 2
这样的索引来匹配它们? (2 1 3 4 1 2) 1
。
print(list(enumerate(x_test,y_test)))
错误:
'list' object cannot be interpreted as an integer
print(list(enumerate(x_test,y_test)))
print(list(enumerate(x_test,y_test)))
错误:
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
您应该使用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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.