Created
October 22, 2019 23:02
-
-
Save albertyumol/2d58c12acc98fcc7c5242c05377805c8 to your computer and use it in GitHub Desktop.
Calculating mode in Python.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import Counter | |
def mode(x): | |
counts = Counter(x) | |
max_count = max(counts.values()) | |
return [i for i, j in counts.items() if j == max_count] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment