Skip to content

Instantly share code, notes, and snippets.

@f0lie
Last active November 1, 2020 10:22
Show Gist options
  • Save f0lie/30c917594c02ea613dc3c3b0ce3b01f5 to your computer and use it in GitHub Desktop.
Save f0lie/30c917594c02ea613dc3c3b0ce3b01f5 to your computer and use it in GitHub Desktop.
Find the mode of a list recursively in Python 3
"""
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