Created
November 4, 2016 10:53
-
-
Save renzon/75cab4c70dfd7d2eaff8bb1db75f8ed5 to your computer and use it in GitHub Desktop.
find_max recursive
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 find_max(iterable): | |
lst = list(iterable) | |
n = len(lst) | |
if n == 0: | |
raise Exception('Not possible finding max of empty') | |
def find_iter(current_max, i): | |
if i == n: | |
return current_max | |
current = lst[i] | |
return find_iter( | |
current_max if current_max >= current else current, | |
i+1 | |
) | |
return find_iter(lst[0], 1) | |
print(find_max(range(3))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment