I'm facing issues with this function. I don't know anything about hashing, but still receive an error about it. The purpose of my function is to give the name of those who have the highest number of activity (activities are the str in the set named "Groupes", and the function return a set with the names and the number of activity. You can see that members names are given in the dictionary "membres_nom" and number are used to call them. Here is the function:
# membres_nom:dict{int:str}
membres_nom = {538:'Dimitri',802:'Elfriede',147:'Bachir', \
125:'Amina',153:'Clovis'}
# groupes : dict[str:set[int]]
groupes = {'cinephiles':{802,125,147,153}, \
'travaux manuels':{125,802,153}, \
'cuisine':{153,147,802}, \
'sport':{153,538,802}}
def suractifs(names, group):
""" Problème Dictionnaire Question 2
dict{int:str} * dict[str:set[int]] -> tuple[Liste[str],int]
"""
# nom : List[str]
nom = []
# nb_activites : List[int]
nb_activites = []
# s : List[str]
# n : int
# (i, j, nb_maximal) : tuple[int,int,int]
i = 0
nb_maximal = 0
temp_set = set()
# (numero, k) : tuple[int, str]
for numero in names:
nom.append(names[numero])
nb_activites.append(0)
for k in group:
if numero in group[k]:
nb_activites[i] += 1
i = i + 1
for j in range(0, len(nb_activites)):
if nb_activites[j] > nb_maximal:
nb_maximal = nb_activites[j]
k = 0
for k in range(0, len(nom)):
if nb_activites[k] == nb_maximal:
temp_set.add(nom[k])
final_set = (temp_set, nb_maximal)
return final_set