Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def pluralityRule():
- candidates = { 'Trump': 0, 'Clinton': 0, 'Johnson': 0 }
- for vote in votes:
- for group in vote['groups']:
- candidates[group['order'][0]] += group['votes']
- return max(candidates, key=candidates.get)
- def pluralityRuleRunoff():
- candidates = { 'Trump': 0, 'Clinton': 0, 'Johnson': 0 }
- for vote in votes:
- for group in vote['groups']:
- candidates[group['order'][0]] += group['votes']
- candidates.pop(min(candidates, key=candidates.get), None)
- for candidate in candidates:
- candidates[candidate] = 0
- for vote in votes:
- for group in vote['groups']:
- if group['order'][0] in candidates:
- candidates[group['order'][0]] += group['votes']
- else:
- candidates[group['order'][1]] += group['votes']
- return max(candidates, key=candidates.get)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement