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. -- https://mail.python.org/mailman/listinfo/python-list