Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #106969 > unrolled thread
| Started by | justin walters <walters.justin01@gmail.com> |
|---|---|
| First post | 2016-04-13 19:37 -0700 |
| Last post | 2016-04-13 19:37 -0700 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Looking for feedback on weighted voting algorithm justin walters <walters.justin01@gmail.com> - 2016-04-13 19:37 -0700
| From | justin walters <walters.justin01@gmail.com> |
|---|---|
| Date | 2016-04-13 19:37 -0700 |
| Subject | Looking for feedback on weighted voting algorithm |
| Message-ID | <mailman.89.1460601435.15650.python-list@python.org> |
Hi all,
I'm looking for feedback on the below vote weighting algorithm which
includes sample input. This is written in Python3.
def weight(votes):
"""
Takes a list of tuples in the form of '(vote %, weight)' where vote %
is the
rating that a user gave and weight is the number of votes it counts as.
Returns the average score based on votes and vote weight.
"""
sum_of_votes = 0
num_of_votes = 0
for vote, weight in votes:
sum_of_votes += vote * weight
num_of_votes += weight
score = sum_of_votes/num_of_votes
return score
if __name__ == '__main__':
votes = [(72, 4), (96, 3), (48, 2), (53, 1), (26, 4), (31, 3), (68, 2),
(91, 1)]
print(weight(votes))
Specifically, I'm wondering if this is a good algorithm for weighted
voting. Essentially a vote is weighted by the number of votes it counts as.
I realize that this is an extremely simple algorithm, but I was wondering
if anyone had suggestions on how to improve it. Thank you for your time.
Back to top | Article view | comp.lang.python
csiph-web