my mode 28 29 python

Solutions on MaxInterview for my mode 28 29 python by the best coders in the world

showing results for - "my mode 28 29 python"
Mikayla
16 Feb 2016
1>>> from collections import Counter
2
3>>> def my_mode(sample):
4...     c = Counter(sample)
5...     return [k for k, v in c.items() if v == c.most_common(1)[0][1]]
6...
7
8>>> my_mode(["male", "male", "female", "male"])
9['male']
10
11>>> my_mode(["few", "few", "many", "some", "many"])
12['few', 'many']
13
14>>> my_mode([4, 1, 2, 2, 3, 5])
15[2]
16
17>>> my_mode([4, 1, 2, 2, 3, 5, 4])
18[4, 2]
19