On Thu, Mar 26, 2015 at 4:17 AM, <humbed...@apache.org> wrote:
>...

> +++ steve/trunk/pysteve/lib/plugins/fic.py Thu Mar 26 09:17:56 2015
>
>...

> @@ -65,15 +65,17 @@ def tallyFIC(votes, issue):
>              matrix[letter] += numseats - i
>              i += 1
>
> +
>      # Start counting
> -    winners = [l for l in matrix if matrix[l] in heapq.nlargest(numseats,
> matrix.values())]
> +    sorted_matrix = sorted(matrix.items(), key=operator.itemgetter(1))
> +    winners = [l[0] for l in sorted_matrix if matrix[l[0]] in
> heapq.nlargest(numseats, matrix.values())]
>
>      # Compile list of winner names
>      winnernames = []
>      x = 0
>      for c in winners:
>          i = ord(c) - ord('a')
> -        winnernames.append("%s ( %u)" % ( candidates[i],
> heapq.nlargest(numseats, matrix.values())[x]))
> +        winnernames.append("%s (%u points)" % ( candidates[i],
> heapq.nlargest(numseats, matrix.values())[x]))
>

I realize that we aren't dealing with time sensitive code, and the data
sets are not large ... but the above irks me. The heapq.nlargest() is
performed on each iteration of the list comprehension, and on each
iteration of the for-loop. Yet the result appears to be constant across all
these loops. ?

Cheers,
-g

Reply via email to