Note that it is possible to have someone write in the same name for multiple different offices, so you do need to be careful to only count occurrences of the name present in the column representing the office you're counting votes for. You are permitted to import the csv module, but this is not required. Hints: Be careful when the request is for the last column in the file - if you're splitting by comma, then that column will contain the '\n' character, and this shouldn't be included in the candidate names, or in the name of the office. You can assume for the sake of simplicity that no candidate or office will contain a comma in the name. Disclaimer: The data in the CSV files was randomly generated from all names available on the ballot for a given district according to https://myballotmn.sos.state.mn.us/ (along with a few fictional characters to simulate write-ins). Don't take any given candidate randomly getting more "votes" than another as an endorsement. Examples (assumes that you have the sample files from hw09files.zip downloaded to the same directory that you're running Python in): >>> count_votes('district_0z.csv', 'County Sheriff') {'Shallan Davar': 1, 'Liz Lemon': 3, 'Ron Swanson': 1} >>> count_votes('district_4b.csv', 'Mayor') {'Shelly Carlson': 7, 'Donna Meagle': 2, 'Kevin Nese Shores': 5} >>> count_votes('district_60b.csv', 'County Commissioner District 4') {'Angela Conley': 50, 'Monkey D. Luffy': 1, 'Jobu Tupaki': 2, 'Leslie Knope': 1}
Note that it is possible to have someone write in the same name for multiple different offices, so you do need to be careful to only count occurrences of the name present in the column representing the office you're counting votes for. You are permitted to import the csv module, but this is not required. Hints: Be careful when the request is for the last column in the file - if you're splitting by comma, then that column will contain the '\n' character, and this shouldn't be included in the candidate names, or in the name of the office. You can assume for the sake of simplicity that no candidate or office will contain a comma in the name. Disclaimer: The data in the CSV files was randomly generated from all names available on the ballot for a given district according to https://myballotmn.sos.state.mn.us/ (along with a few fictional characters to simulate write-ins). Don't take any given candidate randomly getting more "votes" than another as an endorsement. Examples (assumes that you have the sample files from hw09files.zip downloaded to the same directory that you're running Python in): >>> count_votes('district_0z.csv', 'County Sheriff') {'Shallan Davar': 1, 'Liz Lemon': 3, 'Ron Swanson': 1} >>> count_votes('district_4b.csv', 'Mayor') {'Shelly Carlson': 7, 'Donna Meagle': 2, 'Kevin Nese Shores': 5} >>> count_votes('district_60b.csv', 'County Commissioner District 4') {'Angela Conley': 50, 'Monkey D. Luffy': 1, 'Jobu Tupaki': 2, 'Leslie Knope': 1}
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
In python

Transcribed Image Text:Note that it is possible to have someone write in the same
name for multiple different offices, so you do need to be
careful to only count occurrences of the name present in
the column representing the office you're counting votes
for.
You are permitted to import the csv module, but this is
not required.
Hints:
Be careful when the request is for the last column
in the file - if you're splitting by comma, then that
column will contain the '\n' character, and this
shouldn't be included in the candidate names, or
in the name of the office.
You can assume for the sake of simplicity that no
candidate or office will contain a comma in the
name.
Disclaimer: The data in the CSV files was randomly
generated from all names available on the ballot for a
given district according to
https://myballotmn.sos.state.mn.us/ (along with a few
fictional characters to simulate write-ins). Don't take any
given candidate randomly getting more "votes" than
another as an endorsement.
Examples (assumes that you have the sample files from
hw09files.zip downloaded to the same directory that
you're running Python in):
>>> count_votes('district_0z.csv', 'County
Sheriff')
{'Shallan Davar': 1, 'Liz Lemon': 3, 'Ron
Swanson': 1}
>>> count_votes('district_4b.csv',
'Mayor')
{'Shelly Carlson': 7, 'Donna Meagle': 2,
'Kevin Nese Shores': 5}
>>> count_votes('district_60b.csv',
'County Commissioner District 4')
{'Angela Conley': 50, 'Monkey D. Luffy':
1, 'Jobu Tupaki': 2, 'Leslie Knope': 1}

Transcribed Image Text:Minnesota is holding elections on the day that this
assignment is due! We can help them count results by
writing a program. Assume that each district copiles
votes into a CSV file, where each row contains one
citizen's ballot data, and each column represents a
different office up for election. The first row is header
data indicating what office each column represents.
Mayor
Jobu Tupaki
Evelyn Wang
Trevor Belmont
Leslie Knope
April Ludgate
●
●
County Sheriff
Shallan Davar
Liz Lemon
Liz Lemon
Liz Lemon
Ron Swanson
For example, the CSV file above would represent a
district with three offices up for election, and five citizens
who voted.
Governor
Buffy Summers
Leslie Knope
Gordon Freeman
and so on...
Monkey D. Luffy
Buffy Summers
The first voted for Jobu Tupaki for Mayor, Shallan
Davar for Sheriff, and Buffy Summers for
Governor.
The second voted for Evelyn Wang for Mayor, Liz
Lemon for Sheriff, and Leslie Knope for
Governor.
We're going to be creating a dictionary representing the
vote counts for a specific office. For example, in the
spreadsheet above, if I wanted a dictionary of vote counts
for the office of County Sheriff, the result would be:
{'Shallan Davar': 1, 'Liz Lemon': 3, 'Ron
Swanson': 1}
Whereas the vote counts for Governor would be:
{'Buffy Summers': 2, 'Leslie Knope': 1,
'Gordon Freeman': 1,
'Monkey D. Luffy': 1}
Write a function that count_votes (district,
office) that takes in two strings as parameters.
●
district should be the name of a file containing
all voting data for a given district, in the format
specified above. You can assume that said file
actually exists (no need for a try-except block).
• office should be the name of one of the column
titles present in the CSV file. You can assume
that the office passed in will match one of the
columns in the CSV file.
The function should return a dictionary in which each
key is a name present in the column corresponding to the
given office, and the value represents how many times
that name occurs within the column.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 3 images

Recommended textbooks for you

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education

Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY