Last active
November 15, 2018 11:07
-
-
Save abdul-sami/4d6c5d7b3a4b71b89e076597a0c72498 to your computer and use it in GitHub Desktop.
Find `mode` of a list of integers in Python
This file contains hidden or 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
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