Question: Language: Python Program used: PyCharm Interpreter: 3.6.1 at ~/anaconda/bin/python ----- ----- Starter code: https://pastebin.com/NgrECZQ7 candidates_2016: https://www.dropbox.com/s/oc8ws0qfz01664n/sk_election_candidates_2016.csv?dl=1 votecounts_2016: https://www.dropbox.com/s/ucgaf263q2x3qrm/sk_election_votecounts_2016.csv?dl=1 ----- YOU JUST NEED QUESTION #3 FROM

Language: Python

Program used: PyCharm

Interpreter: 3.6.1 at ~/anaconda/bin/python

-----

Language: Python Program used: PyCharm Interpreter: 3.6.1 at ~/anaconda/bin/python ----- ----- Starter

-----

Starter code: https://pastebin.com/NgrECZQ7

candidates_2016: https://www.dropbox.com/s/oc8ws0qfz01664n/sk_election_candidates_2016.csv?dl=1

votecounts_2016: https://www.dropbox.com/s/ucgaf263q2x3qrm/sk_election_votecounts_2016.csv?dl=1

-----

YOU JUST NEED QUESTION #3 FROM THE STARTER CODE PROVIDED ABOVE.

Question 3 (4 points): Purpose: To practice dictionaries as databases. Degree of Difficulty: Easy to Moderate Task: Write a function named index_all_districts that takes three arguments: a list of vote counts for each district, a list of candidates for each district (examples of both seen below) and a list of party names. Your function will return a database, that is, a dictionary that stores all information about each district, keyed by the district name (see the example below) Example: Below, two lists are defined for an election in 2 districts: parties 'LIB', 'NDP' , 'PC', 'SK'] votes- 'Arm River',241,1457,338,207], ['Athabasca',53,1756,0,262] ] cands = [ [,Arm River, , , Russ, , , Denise , , , Raymond, , , Greg, ] , L'Athabasca', 'Michael', 'Buckley','', 'Philip'] ] The votes list has 2 sublists, and each sublist shows the vote count for one particular district. The cands list has 2 sublists as well, and each sublist shows the candidates for the same two districts. With the above lists as arguments, your function should create a dictionary with the following structure Arm River': Name: 'Arm River 'Candidates''LIB' ' Russ', NDP':'Denise', 'PC' Raymond', 'SK' 'Greg' Votes ':LIB':207, NDP :1457, PC': 338, SK': 6187 , Athabasca: [ Name'Athabasca ' , 'Candidates''LIB''Michael', 'NDP'Buckley', 'PC''', 'SK': 'Philip', Votes ':'LIB':262, NDP :1756, PC':0, SK:644 Details: Assume all the districts in the province will be represented in both lists, and that order of the data in the lists is consistent. The example above was small so that you could see what's going on. We'll be calling the output of index_all_districts a district database. Each district name is a key, and its value is a district record, as returned by index_district ) (the function you wrote in Question 2). Your work will be to provide the appropriate arguments for index_district), and what to do with the record it returns. This is the most important part of the whole application. With this districts database, we can do a lot of things, like calculating the winning party, summarizing each party's performance and more! Testing: Before going on, you want to be sure that your function works properly. The starter file has the testing code, but it will be initially part of a comment. Uncomment the testing for this question while you are working on it and comment it out when you are finished

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!