Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.81 KB | None | 0 0
  1. def pluralityRule():
  2.   candidates = { 'Trump': 0, 'Clinton': 0, 'Johnson': 0 }
  3.   for vote in votes:
  4.     for group in vote['groups']:
  5.       candidates[group['order'][0]] += group['votes']
  6.   return max(candidates, key=candidates.get)
  7.  
  8. def pluralityRuleRunoff():
  9.   candidates = { 'Trump': 0, 'Clinton': 0, 'Johnson': 0 }
  10.   for vote in votes:
  11.     for group in vote['groups']:
  12.       candidates[group['order'][0]] += group['votes']
  13.   candidates.pop(min(candidates, key=candidates.get), None)
  14.   for candidate in candidates:
  15.     candidates[candidate] = 0
  16.   for vote in votes:
  17.     for group in vote['groups']:
  18.       if group['order'][0] in candidates:
  19.         candidates[group['order'][0]] += group['votes']
  20.       else:
  21.         candidates[group['order'][1]] += group['votes']
  22.   return max(candidates, key=candidates.get)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement