Last active
November 1, 2020 10:22
-
-
Save f0lie/30c917594c02ea613dc3c3b0ce3b01f5 to your computer and use it in GitHub Desktop.
Find the mode of a list recursively in Python 3
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
""" | |
I did this for a discrete math class problem. | |
Basically find the mode of an array recursively. Fun little problem. | |
Use this to understand a basic example of recursion | |
""" | |
def find_mode(array): | |
if len(array) == 1: | |
return array[0] | |
num = array.pop() | |
return max(find_mode(array),num) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment