Created
November 3, 2016 15:27
-
-
Save renzon/b929c8e8fa2feee42bd487c035848009 to your computer and use it in GitHub Desktop.
find_max with list
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
# -*- coding: utf-8 -*- | |
from __future__ import absolute_import, unicode_literals | |
def find_max(iterable): | |
lst = list(iterable) | |
if len(lst) == 0: | |
raise Exception('Not possible finding max of empty') | |
def find_iter(current_max): | |
if lst: | |
current = lst.pop() | |
return find_iter( | |
current_max if current_max >= current else current) | |
return current_max | |
return find_iter(lst.pop()) | |
print(find_max(range(3))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment