并行迭代:同时并行遍历两个列表
for line1,line2 in zip(line1_list, line2_list):
...
无聊,贴一段刚才的代码:
import sys
import string expected=""
result="" if sys.argv[1] == '--help':
print 'example: --expected=expected --result=result'
if len(sys.argv) < 3:
print 'please provide correct file path'
sys.exit() index = 1
while index < 3:
if sys.argv[index].startswith('--expected'):
expected = sys.argv[index][11:]
elif sys.argv[index].startswith('--result'):
result = sys.argv[index][9:]
index += 1 expected_input = open(expected, 'r')
result_input = open(result, 'r')
expected_lines = expected_input.readlines()
result_lines = result_input.readlines()
expected_input.close()
result_input.close() correct = 0
wrong = 0 if len(expected_lines) != len(result_lines):
print "line counts are not consistent"
else:
for exp, res in zip(expected_lines, result_lines):
if exp == res:
correct += 1
else:
wrong += 1 accuracy = float(correct) / (correct + wrong)
print "All: " + str(correct + wrong) + " Correct: " + str(correct);
print "Accuracy = " + str(accuracy)