Created
November 3, 2016 15:18
-
-
Save renzon/78c86bb6a30c37c2f6245fd62fcd4826 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
# -*- coding: utf-8 -*- | |
from __future__ import absolute_import, unicode_literals | |
def find_max(iterable): | |
iterator = iter(iterable) | |
def find_iter(current_max): | |
try: | |
current = next(iterator) | |
except StopIteration: | |
return current_max | |
else: | |
current_max = current_max if current_max >= current else current | |
return find_iter(current_max) | |
try: | |
return find_iter(next(iterator)) | |
except StopIteration: | |
raise Exception('Not possible finding max of empty') | |
print(find_max(range(3))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment