Advertisement
CR7CR7

frequent

May 14th, 2022
965
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.52 KB | None | 0 0
  1. n=int(input())
  2. myList=[]
  3. for i in range(n):
  4.     next_number=input()
  5.     myList.append(next_number)
  6.  
  7.  
  8.  
  9. mostFreqenNum = {}
  10. contMostnum = 0
  11. #myList = [4 ,1 ,1, 4 ,2, 3, 4, 4, 1 ,2, 4, 9, 3]
  12.  
  13. for i in myList:
  14.     if i in mostFreqenNum:
  15.         mostFreqenNum[i] += 1
  16.     else:
  17.         mostFreqenNum[i] = 1
  18.        
  19. for x in mostFreqenNum:
  20.     if mostFreqenNum[x] > contMostnum:
  21.         contMostnum = mostFreqenNum[x]
  22.         mostFreqKey = x
  23.     else:
  24.         continue
  25.  
  26. print(f' {mostFreqKey} ({contMostnum} times)')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement