Python program to Get the Most Occurrent Element

from random import random
x = [int(random()*100)for i in range(20)]
print(x)
myset = set(x)
highest = None
frequent = 0
for item in myset:
 freq = x.count(item)
 if freq > frequent:
     frequent = freq
     highest = item
print("The highest occurrent element is ", highest)

 

 

 

Output:

[61, 87, 25, 83, 76, 55, 14, 71, 33, 46, 20, 75, 20, 7, 39, 90, 78, 29, 55, 78]
The highest occurrent element is  78

 

Subscribe For Daily Updates