PARTY_INDICES = ['NDP_INDEX', 'GREEN_INDEX', 'LIBERAL_INDEX', 'CPC_INDEX']
party_dic = {}
for i, item in enumerate(PARTY_INDICES):
party_dic[item.split('_')[0]] = i
print party_dic
def voting_borda(*args):
results = {}
for sublist in args:
for i in range(0, 3):
if sublist[i] in results:
results[sublist[i]] += 3-i
else:
results[sublist[i]] = 3-i
winner = max(results, key=results.get)
results = [v for k, v in sorted(results.items(), key = lambda x: party_dic[x[0]])]
return winner, results
print voting_borda(['GREEN','NDP', 'LIBERAL', 'CPC'],['GREEN','CPC','LIBERAL','NDP'],['LIBERAL','NDP', 'CPC', 'GREEN'])
{'NDP': 0, 'CPC': 3, 'GREEN': 1, 'LIBERAL': 2}
('GREEN', [4, 6, 5, 3])