+ 1
Most appeared element in a list, error, How to Solve?
#Write a Python program to find the most appeared element in a list. List = [1, 5, 3, 7, 2, 10, 7, 2, 5, 5, 13, 7, 18] def MyFunc(List): return List.count(i) result = List.sort(key = MyFunc) # sort digits accordance their frequency print(result[-1])
2 Answers
+ 2
You're pretty close
List = [1, 5, 3, 7, 2, 10, 7, 2, 5, 5, 13, 7, 18]
def MyFunc(i):
return List.count(i)
result = sorted(List, key=MyFunc)
print(result[-1])
+ 1
Thank you so much, I guessed that only sort() should be used, cause of List in it.