Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #106969

Looking for feedback on weighted voting algorithm

From justin walters <walters.justin01@gmail.com>
Newsgroups comp.lang.python
Subject Looking for feedback on weighted voting algorithm
Date 2016-04-13 19:37 -0700
Message-ID <mailman.89.1460601435.15650.python-list@python.org> (permalink)
References <CAO1D73EFoLoJm=4shNfgEsJinGHrM82J_BsTRMnm7XX4tW1h+A@mail.gmail.com>

Show all headers | View raw


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 comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Looking for feedback on weighted voting algorithm justin walters <walters.justin01@gmail.com> - 2016-04-13 19:37 -0700

csiph-web