davegimo

Untitled

Jun 4th, 2022
1,002
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.52 KB | None | 0 0
  1. #contare occorrenze voti per ogni persona, restituire la persona con piu voti
  2.  
  3. def esercizio(l):
  4.  
  5.     d = {}
  6.  
  7.     for element in l:
  8.         if element in d:
  9.             d[element] += 1
  10.         else:
  11.             d[element] = 1
  12.  
  13.     valmax = 0
  14.     elementomax = ""
  15.    
  16.     for key in d:
  17.         if d[key] > valmax:
  18.             valmax = d[key]
  19.             elementomax = key
  20.  
  21.  
  22.     return elementomax
  23.  
  24.  
  25.  
  26. l = ["davide","giorgio","davide","giorgio","davide","davide","francesco","sara"]
  27.  
  28.  
  29. print(esercizio(l))
  30.  
Advertisement
Add Comment
Please, Sign In to add comment