Skip to content

Instantly share code, notes, and snippets.

@neuromusic
Created October 2, 2018 04:36
Show Gist options
  • Save neuromusic/0f3c70fff0f95cdbd1bbee7b433877c0 to your computer and use it in GitHub Desktop.
Save neuromusic/0f3c70fff0f95cdbd1bbee7b433877c0 to your computer and use it in GitHub Desktop.
pure python mode
def mode(vals):
unique = set(vals)
unique, counts = zip(*((v,vals.count(v)) for v in unique))
return unique[counts.index(max(counts))]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment