1. Obtain the largest element of the array (with the max function)
>>> a = [1,2,2,4,3,6,3,9] >>> max(set(a),key = a.count) 2
Obviously the above is missing three, I feel that the data is to be rigorous, 2 and 3 also satisfy the requirements dropped 3 is very foolish.
2. Use the function Counter, can be obtained quickly list the number of times each element appears
>>> from collections import Counter >>> a [1, 2, 2, 4, 3, 6, 3, 9] >>> Counter(a) Counter({2: 2, 3: 2, 1: 1, 4: 1, 6: 1, 9: 1})
Most characters that appear in the list of the calculation method Address : https://www.cnblogs.com/Lands-ljk/p/5764003.html