Created
May 8, 2017 02:32
-
-
Save mayonesa/4fa6e4a79b1f5fb76cb0982dcfd91776 to your computer and use it in GitHub Desktop.
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
def mode(data): | |
def loop(i, counts, c_max): | |
max_val = c_max[0] | |
if (i < 0): | |
return max_val | |
else: | |
c_val = data[i] | |
new_count = counts.get(c_val, 0) + 1 | |
counts[c_val] = new_count | |
max_dup = c_max[1] | |
return loop(i - 1, counts, (c_val, new_count) if new_count > max_dup else c_max) | |
return loop(len(data) - 1, dict(), (float('-inf'), 0)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment