Possible Duplicate:
changing the output
This is the code:
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)
return winner, results
print(voting_borda(
['GREEN','NDP', 'LIBERAL', 'CPC'],
['GREEN','CPC','LIBERAL','NDP'],
['LIBERAL','NDP', 'CPC', 'GREEN']
))
The output produced is
"('GREEN', {'LIBERAL': 5, 'NDP': 4, 'GREEN': 6, 'CPC': 3})"
I don't want the party names in the output (liberal, ndp, green and cpc) I just need the values, How can I edit the code to achieve that?
edit:
the error message i got after testing the above code (with: >>>voting_borda([['NDP', 'CPC', 'GREEN', 'LIBERAL'],['NDP', 'CPC', 'LIBERAL', 'GREEN'],['NDP', 'CPC', 'GREEN', 'LIBERAL']])
Traceback (most recent call last): File "", line 1, in voting_borda([['NDP', 'CPC', 'GREEN', 'LIBERAL'],['NDP', 'CPC', 'LIBERAL', 'GREEN'],['NDP', 'CPC', 'GREEN', 'LIBERAL']]) File "C:\Users\mycomp\Desktop\work\voting_systems.py", line 144, in voting_borda winner = max(results, key=results.get) NameError: global name 'results' is not defined