Skip to content

Instantly share code, notes, and snippets.

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