【发布时间】:2015-01-08 19:30:26
【问题描述】:
这是我当前的代码:
predict_results = []
with open ("newTesting.predict") as inputfile:
for line in inputfile:
predict_results.append(line.strip())
print predict_results
first_list = []
with open ("newTesting") as inputfile:
for line in inputfile:
first_list.append(line.strip().split()[0])
print first_list
if predict_results [0] == first_list[0]:
print True
else:
print False
这是我当前的输出:
['-1', '-1', '-1', '-1', '-1', '-1', '-1', '-1', '-1', ' -1','1','-1','-1','-1','-1','-1','-1','-1','-1','1 ','1','-1','-1','-1','-1','-1','1','-1','-1','-1', '-1'、'-1'、'-1'、'1'、'-1'、'-1'、'-1'、'1'、'-1'、'1'、'-1 ','-1','-1','-1','-1','1','-1','1','-1','-1','-1', '-1'、'-1'、'-1'、'1'、'-1'、'1'、'-1'、'-1'、'-1'、'-1'、'- 1'、'-1'、'-1'、'-1'、'-1'、'-1'、'-1'、'-1'、'-1'、'-1'、'- 1','-1','1','-1','1','-1','1','-1','-1','-1','-1', '-1'、'-1'、'1'、'1'、'-1'、'1'、'-1'、'1'、'-1'、'1'、'-1'、 '-1'、'1'、'-1'、'-1'、'-1'、'-1'、'-1'、'1'、'-1'、'-1'、'- 1'、'1'、'1'、'-1'、'-1'、'-1'、'-1'、'-1'、'1'、'1'、'-1'、' -1','-1','-1','-1','-1','-1'] ['1', '-1', '1', '-1', '-1', '-1', '-1', '-1', '-1', '1', '1 '、'-1'、'1'、'1'、'1'、'1'、'-1'、'1'、'-1'、'1'、'1'、'1'、' 1'、'-1'、'1'、'-1'、'1'、'1'、'-1'、'-1'、'1'、'1'、'-1'、'1 '、'1'、'-1'、'1'、'1'、'1'、'1'、'-1'、'-1'、'1'、'1'、'1'、' 1'、'1'、'1'、'1'、'-1'、'-1'、'1'、'1'、'-1'、'1'、'-1'、'1' , '-1', '-1', '1', '1', '-1', '1', '1', '1', '-1', '-1', '-1' , '1', '-1', '-1', '1', '1', '1', '-1', '1', '-1', '-1', '-1' , '1', '-1', '-1', '-1', '1', '1', '-1', '-1', '-1', '-1', '- 1'、'1'、'1'、'-1'、'-1'、'1'、'-1'、'1'、'1'、'1'、'-1'、'1' , '-1', '-1', '-1', '1', '1', '-1', '1', '1', '-1', '-1', '-1 ', '-1', '-1', '1', '-1', '-1', '-1', '-1', '-1']
错误
我只能检查索引 [0] 是否正确。如何使用 first_list 检查 predict_results 中的所有索引
谢谢
【问题讨论】:
标签: list python-2.7 indexing compare