Skip to content

Instantly share code, notes, and snippets.

@renzon
Created November 3, 2016 15:18
Show Gist options
  • Save renzon/78c86bb6a30c37c2f6245fd62fcd4826 to your computer and use it in GitHub Desktop.
Save renzon/78c86bb6a30c37c2f6245fd62fcd4826 to your computer and use it in GitHub Desktop.
# -*- 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