Note that there are some explanatory texts on larger screens.

plurals
  1. POHow would I form this function using the indicies and dictionary
    primarykey
    data
    text
    <pre><code> NDP_INDEX = 0 GREEN_INDEX = 1 LIBERAL_INDEX = 2 CPC_INDEX = 3 </code></pre> <p>Let's say there is a constant</p> <pre><code> PARTY_INDICES = [NDP_INDEX, GREEN_INDEX, LIBERAL_INDEX, CPC_INDEX] INDEX_TO_NAME = {NDP_INDEX: 'NDP', GREEN_INDEX: 'GREEN', LIBERAL_INDEX:'LIBERAL' CPC_INDEX: 'CPC'} NAME_TO_INDEX = {'NDP':NDP_INDEX, 'GREEN':GREEN_INDEX, 'LIBERAL':LIBERAL_INDEX, 'CPC':CPC_INDEX} def voting_plurality(votes): '''(list of str) -&gt; (list of int) </code></pre> <p>The parameter is a list of single-candidate ballots for a single riding.</p> <p>In Plurality Voting, the party that receives the most votes wins the seat. We have provided the header and docstring for this function in the starter code.</p> <p>Return a list of int where the element is a four-element list that contains the number of ballots for each party. The order of the list elements corresponds to the order of the parties in PARTY_INDICES.</p> <pre><code> &gt;&gt;&gt;voting_plurality(['GREEN', 'GREEN', 'NDP', 'GREEN', 'CPC']) [1,3,0,1] ''' party_list = [0, 0, 0, 0] #These Gaps need filled out return party_list </code></pre> <p>Using no imported program such as enumerate or lambda or such and using the dictionary INDEX_TO_NAME and NAME_TO_INDEX, I need an output of [1,3,0,1] and output is [1,3,0,1] is because There are 3 'GREEN' votes and 'GREEN' is second on the index of PARTY_INDICES, there are 1 'NDP' vote and 'NDP' is first on the index of PARTY_INDICES, there are no 'Liberal' vote and 'Liberal' is third on the index of PARTY_INDICES and there are 1 'CPC' vote and 'CPC' is last on the index of PARTY_INDICES. party_list is created and it is used to count the number of votes according to the index of PARTY_INDICES.</p> <p>Output needs to be [1,3,0,1], I hope this made more sense to people. Please help out. Thank you </p>
    singulars
    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.
    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