We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent de0dc99 commit 141fe19Copy full SHA for 141fe19
majority_vote.py
@@ -0,0 +1,29 @@
1
+# -*- coding: utf-8 -*-
2
+"""
3
+Created on Thu Nov 16 21:04:20 2017
4
+
5
+@author: Prince Adeyemi
6
7
8
+import random
9
10
11
+def majority_vote(votes):
12
+ """Calculate and select majority vote from a list of votes"""
13
14
+ vote_counts = {}
15
+ for vote in votes:
16
+ if vote in vote_counts:
17
+ vote_counts[vote] += 1
18
+ else:
19
+ vote_counts[vote] = 1
20
21
+ #Choose a winner
22
+ winner = []
23
+ max_count = max(vote_counts.values())
24
+ #loop over vote and count
25
+ for vote, count in vote_counts.items():
26
+ if count == max_count:ype
27
+ winner.append(vote)
28
29
+ return random.choice(winner)
0 commit comments