Skip to content

Instantly share code, notes, and snippets.

@albertyumol
Created October 22, 2019 23:02
Show Gist options
  • Save albertyumol/2d58c12acc98fcc7c5242c05377805c8 to your computer and use it in GitHub Desktop.
Save albertyumol/2d58c12acc98fcc7c5242c05377805c8 to your computer and use it in GitHub Desktop.
Calculating mode in Python.
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