Candidates

A votes dictionary is a dictionary (dict) that represents the votes received by the mayor candidates of a municipality. The key of the dictionary is the name and surname of the candidate (str), and the value is the number of received votes (int). For example:

{'Joan Pere Jorbina Palau':570, 'Niceto Brunildo Fornells':679,
'Mariona Puig Peix': 701, 'Adriana de Tor Quemada': 451}

An income dictionary is a dictionary (dict) that represents the annual income of all the people of the municipality. The key of the dictionary is the name and surnames of the person (str) and the value is their annual income expressed in euros (int). For example:

{'Mariona Puig Peix':15456, 'Arnau Osorio Lucas':27654,
 'Arnau Brigat Pelfred': 18654, 'Niceto Brunildo Fornells':14567}

Save all functions into the same file named candidates.py.

votes_minimum(dic, threshold)

Given a votes dictionary as the one described and a threshold (int), return a Boolean (bool) with a value of True if all candidates reached a number of votes superior to the given threshold, and False otherwise. For example,

>>> dic = {'Joan Pere Jorbina Palau':678,
... 'Niceto Brunildo Fornells':570, 'Mariona Puig Peix': 701,
... 'Adriana de Tor Quemada': 451}
>>> votes_minimum (dic, 400)
True
>>> votes_minimum (dic, 600)
False

Note

More tests are provided in file test-votes_minimum.txt.

can_most_voted(dic)

Given a votes dictionary as the one described, return the name and surname of the most voted candidate (str). If the given dictionary is empty, return an empty string. You can suppose that there are no repeated number of votes. For example,

>>> dic = {'Joan Pere Jorbina Palau':570, 
... 'Niceto Brunildo Fornells':679, 'Mariona Puig Peix': 701,
... 'Adriana de Tor Quemada': 451}
>>> can_most_voted(dic)
'Mariona Puig Peix'

Note

More tests are provided in file test-can_most_voted.txt.

votes_income(dvotes, dinc)
Given a votes dictionary and an income dictionary as the ones

described, return a list with the names (str) of those candidates whom we don’t known the income, that is, those candidates that are in the votes dictionary but not in the income dictionary. The returned list must be sorted alphabetically:

>>> dvotes = {'Joan Pere Jorbina Palau':570, 
... 'Niceto Brunildo Fornells':679, 'Mariona Puig Peix': 701, 
... 'Adriana de Tor Quemada': 451}
>>> dinc = {'Mariona Puig Peix':15456, 'Arnau Osorio Lucas':27654, 
... 'Arnau Brigat Pelfred': 18654, 'Niceto Brunildo Fornells':14567}
>>> votes_income(dvotes, dinc)
['Adriana de Tor Quemada', 'Joan Pere Jorbina Palau']

Note

More tests are provided in file test-votes_income.txt.

wealthy(dvotes, dinc)

Given a votes dictionary and an income dictionary as the ones decribed, return a list with the names (str) of the 10 wealthiest people in the municipality. In addition, for each one of these people that is a candidate, we must place an asterisk ('*') next to their name. The list must be sorted from more to less income. Suppose that there are at least 10 people in the municipality. For example,


>>> dvotes = {'Joan Pere Jorbina Palau':570, 'Gil Palomo Como': 743, 
... 'Niceto Brunildo Fornells':679, 'Mariona Puig Peix': 701, 
... 'Adriana de Tor Quemada': 451, 'Lola Cano Mur': 590, 'Marc Pla Rey': 468}
>>> dinc = {'Mariona Puig Peix':15456, 'Arnau Osorio Lucas':27654, 
... 'Arnau Brigat Pelfred': 18654, 'Niceto Brunildo Fornells':14567, 
... 'Pere Pi Pera': 100200, 'Montse Gil Gibert': 115200, 
... 'Ana Perez Juan': 200125, 'Gil Palomo Como': 34800, 
... 'Joan Petit Balla': 43000, 'Elena Pez Paz': 29000, 
... 'Iu Quer Vall': 13000, 'Luz Bayo Cal': 25000, 'Pau Bru Bou': 10000, 
... 'Pol Coll Mas': 12000, 'Lola Cano Mur': 10000, 'Marc Pla Rey': 200000}
>>> for person in wealthy (dvotes, dinc):
...   print(person)
Ana Perez Juan
Marc Pla Rey*
Montse Gil Gibert
Pere Pi Pera
Joan Petit Balla
Gil Palomo Como*
Elena Pez Paz
Arnau Osorio Lucas
Luz Bayo Cal
Arnau Brigat Pelfred

Note

More tests are provided in file test-wealthy.txt.

Solutions

A solution is provided in file candidates.py.