nodes: 0, module; 1, function_definition; 2, function_name:vote_mean; 3, parameters; 4, block; 5, identifier:candidates; 6, identifier:votes; 7, identifier:n_winners; 8, expression_statement; 9, expression_statement; 10, for_statement; 11, for_statement; 12, expression_statement; 13, expression_statement; 14, expression_statement; 15, expression_statement; 16, for_statement; 17, return_statement; 18, comment:"""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
      """; 19, assignment; 20, identifier:vote; 21, identifier:votes; 22, block; 23, identifier:s; 24, identifier:sums; 25, block; 26, assignment; 27, call; 28, assignment; 29, assignment; 30, identifier:e; 31, identifier:best; 32, block; 33, identifier:d; 34, identifier:sums; 35, dictionary_comprehension; 36, for_statement; 37, expression_statement; 38, identifier:ordering; 39, call; 40, attribute; 41, argument_list; 42, identifier:best; 43, subscript; 44, identifier:d; 45, list; 46, for_statement; 47, pair; 48, for_in_clause; 49, identifier:v; 50, identifier:vote; 51, block; 52, assignment; 53, identifier:list; 54, argument_list; 55, identifier:ordering; 56, identifier:sort; 57, keyword_argument; 58, keyword_argument; 59, identifier:ordering; 60, slice; 61, identifier:c; 62, identifier:candidates; 63, block; 64, call; 65, list; 66, identifier:candidate; 67, identifier:candidates; 68, expression_statement; 69, subscript; 70, binary_operator:sum(sums[s]) / len(sums[s]); 71, call; 72, identifier:key; 73, call; 74, identifier:reverse; 75, True; 76, call; 77, if_statement; 78, identifier:str; 79, argument_list; 80, call; 81, identifier:sums; 82, identifier:s; 83, call; 84, call; 85, attribute; 86, argument_list; 87, attribute; 88, argument_list; 89, identifier:min; 90, argument_list; 91, comparison_operator:str(c) == e[0]; 92, block; 93, identifier:candidate; 94, attribute; 95, argument_list; 96, identifier:sum; 97, argument_list; 98, identifier:len; 99, argument_list; 100, identifier:sums; 101, identifier:items; 102, identifier:operator; 103, identifier:itemgetter; 104, integer:1; 105, identifier:n_winners; 106, call; 107, call; 108, subscript; 109, expression_statement; 110, subscript; 111, identifier:append; 112, subscript; 113, subscript; 114, subscript; 115, identifier:len; 116, argument_list; 117, identifier:str; 118, argument_list; 119, identifier:e; 120, integer:0; 121, call; 122, identifier:sums; 123, call; 124, identifier:v; 125, integer:1; 126, identifier:sums; 127, identifier:s; 128, identifier:sums; 129, identifier:s; 130, identifier:ordering; 131, identifier:c; 132, attribute; 133, argument_list; 134, identifier:str; 135, argument_list; 136, identifier:d; 137, identifier:append; 138, tuple; 139, subscript; 140, identifier:c; 141, subscript; 142, identifier:v; 143, integer:0; 144, identifier:e; 145, integer:1
code: def vote_mean(candidates, votes, n_winners):
      """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
      """
      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