Q:

my_mode() python

>>> from collections import Counter

>>> def my_mode(sample):
...     c = Counter(sample)
...     return [k for k, v in c.items() if v == c.most_common(1)[0][1]]
...

>>> my_mode(["male", "male", "female", "male"])
['male']

>>> my_mode(["few", "few", "many", "some", "many"])
['few', 'many']

>>> my_mode([4, 1, 2, 2, 3, 5])
[2]

>>> my_mode([4, 1, 2, 2, 3, 5, 4])
[4, 2]
0

New to Communities?

Join the community