# create votes, an empty list votes = [] # open votes.txt file votes_file = open('votes.txt', 'r') # read the next line in the file # end of file? for line in votes_file: # split line at commas and read first value line = line.strip().split(',') vote = line[0] # append value to votes list votes.append(vote) # create votes_count, an empty dictionary votes_count = {} # read next item in votes list # end of list? for vote in votes: # is candidate already in votes_count? if vote in votes_count: # add 1 to candidate's value votes_count[vote] += 1 else: # store a new key in votes_count with candidate's name and value = 1 votes_count[vote] = 1 # create winner as empty string and max_votes = 0 winner = "" max_votes = 0 # read next candidate in votes_count # end of dictionary? for candidate in votes_count: # is value > max_votes? if votes_count[candidate] > max_votes: # set max_votes = value, winner = key max_votes = votes_count[candidate] winner = candidate # print winner, max_votes print(winner, "wins the election with", max_votes, "votes.")