python并行迭代

并行迭代:同时并行遍历两个列表

for line1,line2 in zip(line1_list, line2_list):

    ...

无聊,贴一段刚才的代码:

 1 import sys
 2 import string
 3 
 4 expected=""
 5 result=""
 6 
 7 if sys.argv[1] == '--help':
 8   print 'example: --expected=expected --result=result'
 9 if len(sys.argv) < 3:
10   print 'please provide correct file path'
11   sys.exit()
12 
13 index = 1
14 while index < 3:
15   if sys.argv[index].startswith('--expected'):
16     expected = sys.argv[index][11:]
17   elif sys.argv[index].startswith('--result'):
18     result = sys.argv[index][9:]
19   index += 1
20 
21 expected_input = open(expected, 'r')
22 result_input = open(result, 'r')
23 expected_lines = expected_input.readlines()
24 result_lines = result_input.readlines()
25 expected_input.close()
26 result_input.close()
27 
28 correct = 0
29 wrong = 0
30 
31 if len(expected_lines) != len(result_lines):
32   print "line counts are not consistent"
33 else:
34   for exp, res in zip(expected_lines, result_lines):
35     if exp == res:
36       correct += 1
37     else:
38       wrong += 1
39 
40 accuracy = float(correct) / (correct + wrong)
41 print "All: " + str(correct + wrong) + " Correct: " + str(correct);
42 print "Accuracy = " + str(accuracy) 

 

posted @ 2013-06-26 19:33  常小小  阅读(900)  评论(1编辑  收藏  举报