code: def vote_mean(candidates, votes, n_winners):
      
      sums = {str(candidate): [] for candidate in candidates}
      for vote in votes:
          for v in vote:
              sums[str(v[0])].append(v[1])
      for s in sums:
          sums[s] = sum(sums[s]) / len(sums[s])
      ordering = list(sums.items())
      ordering.sort(key=operator.itemgetter(1), reverse=True)
      best = ordering[:min(n_winners, len(ordering))]
      d = []
      for e in best:
          for c in candidates:
              if str(c) == e[0]:
                  d.append((c, e[1]))
      return d
docs: Perform mean voting based on votes.
  
      Mean voting computes the mean preference for each of the artifact
      candidates from the votes and sorts the candidates in the mean preference
      order.
  
      Ties are resolved randomly.
  
      :param candidates: All candidates in the vote
      :param votes: Votes from the agents
      :param int n_winners: The number of vote winners