比如 7 个同学( M1 - M7 ),他们的回答如下:
M1: 2,3,4,7,9
M2: 4,5,7,8
M3: 3,4,9,11
M4: 4,6,12
M5: 1,2,3,4,5,6,7
M6: 3,4,5,6,7,8
M7: 3,5,7,9
如何知道谁得到最高的同意率。
1
twor2 2015-09-05 01:20:01 +08:00
1 M1= 2,3,4,7,9
2 M2= 4,5,7,8 3 M3= 3,4,9,11 4 M4= 4,6,12 5 M5= 1,2,3,4,5,6,7 6 M6= 3,4,5,6,7,8 7 M7= 3,5,7,9 8 M=M1+M2+M3+M4+M5+M6+M7 9 vote = [0]*20 10 for i in m: 11 ....vote[i] +=1 12 maxnum = max (vote ) 13 print [i for i, j in enumerate (vote ) if j == maxnum] |
2
twor2 2015-09-07 00:47:28 +08:00
from collections import Counter
c = Counter () for i in m: ....c[i] = c[i] + 1 |