Skip to content

Instantly share code, notes, and snippets.

@abdul-sami
Last active November 15, 2018 11:07
Show Gist options
  • Save abdul-sami/4d6c5d7b3a4b71b89e076597a0c72498 to your computer and use it in GitHub Desktop.
Save abdul-sami/4d6c5d7b3a4b71b89e076597a0c72498 to your computer and use it in GitHub Desktop.
Find `mode` of a list of integers in Python
def mode(k):
"""
Returns mode of a list of integers passed as argument
"""
k.sort()
mode=sorted(k,key=k.count,reverse=True)[0]
return mode
integers=[1,2,3,56,83,283,28,232,23,23,23,2,2,2,3,2]
print(mode(integers))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment