Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 #6 FROM
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 #6 FROM THE STARTER CODE PROVIDED ABOVE.
Question 6 (4 points) Purpose: To practice reading data from a file. Degree of Difficulty: Easy Task: Write a function called read party names which takes one argument a string with the name of a vote count file. Your function will read the first line of the file only, and return a list of the party names that appear on that line in the file Example: Remember from the overview that the vote count file is a plain-text, tabular file where the first few lines look Like this: District,GP,LIB,NDP, PC, SK, WIP, IND Arm River,241,207,1457,338,6187,0,0 Athabasca,53,262,1756,0,644,0,0 Batoche,103,216,2114,0,4471,0,0 Your function should return the list ['GP', LIB', NDP' , 'PC', 'SK', 'WIP' , 'IND'] Details: All we want to do here is read the very first line of the file use the readline) method to obtain a single line from the file. Strip the newline character from the end of the line (use the rstrip) method) and split the header line into a list. You may want to refer to Chapter 12 (pp. 96-97) of the textbook. Keep in mind that here, the data is separated by commas, not spaces. Notice that the very first item on the column header line (e.g. "District) is not actually a party name this is just a label for the first column in our tabular file. Remove the first item from your new list, but do so without assuming that the first column will always be labelled "District"! 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. Note that while the "IND" column does not technically represent a party, it is OK for our program to treat it like a party for simplicity. Make sure your function works for tabular files with any number of columnsStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started