Note that there are some explanatory texts on larger screens.

plurals
  1. POChanging the output a bit
    primarykey
    data
    text
    <p>Question is:</p> <pre><code>voting_borda: </code></pre> <p>(list of list of str) -> tuple of (str, list of int)</p> <p>The parameter is a list of 4-element lists that represent rank ballots for a single riding.</p> <p>The Borda Count is determined by assigning points according to ranking. A party gets 3 points for each first-choice ranking, 2 points for each second-choice ranking and 1 point for each third-choice ranking. (No points are awarded for being ranked fourth.) For example, the rank ballot shown above would contribute 3 points to the Liberal count, 2 points to the Green count and 1 point to the CPC count. The party that receives the most points wins the seat.</p> <p>Return a tuple where the first element is the name of the winning party according to Borda Count and the second element is a four-element list that contains the total number of points for each party. The order of the list elements corresponds to the order of the parties in PARTY_INDICES.</p> <p>This is my code:</p> <pre><code>def voting_borda(*args): results = {} for sublist in args: for i in range(0, 3): if sublist[i] in results: results[sublist[i]] += 3-i else: results[sublist[i]] = 3-i winner = max(results, key=results.get) results_sort = sorted(results,key=lambda x:x[1],reverse=True) return winner, results_sort </code></pre> <p>However, if i try </p> <pre><code>voting_borda(['GREEN','NDP', 'LIBERAL', 'CPC'],['GREEN','CPC','LIBERAL','NDP'],['LIBERAL','NDP', 'CPC', 'GREEN']) </code></pre> <p>I get,</p> <pre><code>('GREEN', {'NDP': 4, 'CPC': 3, 'GREEN': 6, 'LIBERAL': 5}) </code></pre> <p>But, I want the first parameter to be the winner(that part is fine), and the second parameter to be just the values and also to be in the order of PARTY_INDICES which is <code>PARTY_INDICES = [NDP_INDEX, GREEN_INDEX, LIBERAL_INDEX, CPC_INDEX]</code>. </p> <p>any solutions or ways that i could make this better?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload