Advertisement
robjones90

Candidates1

Oct 3rd, 2022
836
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. import collections
  2. import functools
  3. import operator
  4.  
  5. #dictionary of data
  6. candidates = [
  7.          {'Joshua': 192,
  8.          'Aldrin': 48,
  9.          'Dianna': 206,
  10.          'Donna': 37,
  11.          'David': 195
  12.          },
  13.          {'Joshua': 200,
  14.          'Aldrin': 200,
  15.          'Dianna': 150,
  16.          'Donna': 67,
  17.          'David': 123
  18.          }]
  19.  
  20.          
  21. def count_votes(candidate_dictionary):
  22.     # sum the values with same keys
  23.     result= dict(functools.reduce(operator.add,
  24.       map(collections.Counter, candidate_dictionary)))
  25.     return result
  26. print(count_votes(candidates))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement