+ 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])

6th Jun 2019, 8:39 PM
L. Yeghiazaryan🇦🇲
L.  Yeghiazaryan🇦🇲 - avatar
2 odpowiedzi
+ 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])
6th Jun 2019, 8:51 PM
Anna
Anna - avatar
+ 1
Thank you so much, I guessed that only sort() should be used, cause of List in it.
6th Jun 2019, 8:59 PM
L. Yeghiazaryan🇦🇲
L.  Yeghiazaryan🇦🇲 - avatar