Skip to content

Instantly share code, notes, and snippets.

@anddam
Last active November 5, 2016 17:58
Show Gist options
  • Save anddam/d10413a5872aa7912f07c1abc2637731 to your computer and use it in GitHub Desktop.
Save anddam/d10413a5872aa7912f07c1abc2637731 to your computer and use it in GitHub Desktop.
# CheckIO mission https://py.checkio.org/mission/min-max/
# Write python implementation of the built-in functions max
#
# max(iterable, *[, key])
# max(arg1, arg2, *args[, key])
def min(*args, **kwargs):
key = kwargs.get("key", lambda x: x)
the_list = list(args[0]) if len(args) == 1 else args
result = the_list[0]
for item in the_list:
if key(item) < key(result):
result = item
return result
def max(*args, **kwargs):
key = kwargs.get("key", lambda x: x)
the_list = list(args[0]) if len(args) == 1 else args
result = list(the_list)[0]
for item in the_list:
if key(item) > key(result):
result = item
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment