Last active
November 5, 2016 17:58
-
-
Save anddam/d10413a5872aa7912f07c1abc2637731 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# 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