본문 바로가기

Python_Matter/Solve

Python Learn the basics Quiz 100

반응형

Q>

In this mission you should write you own py3 implementation (but you can use py2 for this) of the built-in functions min and max.

(이 임무에서 당신은 py3 구현을 작성해야한다 (그러나 py2는 이것을 사용할 수있다). 내장 함수 min과 max.)

Some builtin functions are closed here: import, eval, exec, globals. Don't forget you should implement two functions in your code.

(일부 내장 함수는 여기에서 닫힙니다 : import, eval, exec, globals. 코드에 두 가지 기능을 구현해야한다는 것을 잊지 마십시오.)

max(iterable, *[, key]) or min(iterable, *[, key])

max(arg1, arg2, *args[, key]) or min(arg1, arg2, *args[, key])

 

Return the largest (smallest) item in an iterable or the largest(smallest) of two or more arguments.

(iterable에서 가장 큰 (최소) 항목 또는 둘 이상의 인수 중에서 가장 큰 (가장 작은) 항목을 리턴하십시오.)

If one positional argument is provided, it should be an iterable.

(하나의 위치 인수가 제공되면 iterable이어야합니다.)

The largest (smallest) item in the iterable is returned.

(iterable의 가장 큰 (가장 작은) 항목이 리턴됩니다.)

If two or more positional arguments are provided, the largest (smallest) of the positional arguments is returned.

(두 개 이상의 위치 인수가 제공되면, 가장 큰 (가장 작은) 위치 인수가 리턴됩니다.)

The optional keyword-only key argument specifies a function of one argument that is used to extract a comparison key from each list element (for example, key=str.lower).

(선택적 키워드 전용 키 인수는 각 목록 요소 (예 : key = str.lower)에서 비교 키를 추출하는 데 사용되는 하나의 인수 기능을 지정합니다.)

If multiple items are maximal (minimal), the function returns the first one encountered.

(여러 항목이 최대 (최소)이면 함수는 처음 발생한 항목을 반환합니다. )
-- Python Documentation (Built-in Functions)

 

Input: One positional argument as an iterable or two or more positional arguments.

         (하나의 위치 인수가 반복 가능 또는 둘 이상의 위치 인수로 사용됩니다.)

         Optional keyword argument as a function.

         (선택적 키워드 인수를 함수로 사용합니다.)

 

Output: The largest item for the "max" function and the smallest for the "min" function.

           ( "최대"기능에 대해 가장 큰 항목이고 "최소"기능에 대해 가장 작은 항목입니다.)

 

Example:

max(3, 2) == 3
min(3, 2) == 2
max([1, 2, 0, 3, 4]) == 4
min("hello") == "e"
max(2.2, 5.6, 5.9, key=int) == 5.6
min([[1,2], [3, 4], [9, 0]], key=lambda x: x[1]) == [9, 0]

 

How it is used: This task will help you understand how some of the built-in functions work on a more precise level.

                     (이 태스크는 내장 함수 중 일부가보다 정확한 레벨에서 작동하는 f}을 이해하는 데 도움이됩니다.)

 

Precondition: All test cases are correct and functions don't have to raise exceptions.

                  (모든 테스트 케이스가 정확하며 예외가 발생하지 않아도됩니다.)

 

A>

def min(*args, key=None, rev=False):
    return sorted(args if len(args) > 1 else args[0], key=key, reverse=rev)[0]

def max(*args, key=None):
    return min(*args, key=key, rev=True)

if __name__ == '__main__':
    #These "asserts" using only for self-checking and not necessary for auto-testing
    assert max(3, 2) == 3, "Simple case max"
    assert min(3, 2) == 2, "Simple case min"
    assert max([1, 2, 0, 3, 4]) == 4, "From a list"
    assert min("hello") == "e", "From string"
    assert max(2.2, 5.6, 5.9, key=int) == 5.6, "Two maximal items"
    assert min([[1, 2], [3, 4], [9, 0]], key=lambda x: x[1]) == [9, 0], "lambda key"
    print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")

 

O>

Coding complete? Click 'Check' to review your tests and earn cool rewards!

Process finished with exit code 0

 

S>

https://py.checkio.org

반응형

'Python_Matter > Solve' 카테고리의 다른 글

Python Learn the basics Quiz 102  (0) 2019.06.25
Python Learn the basics Quiz 101  (0) 2019.06.25
Python Learn the basics Quiz 99  (0) 2019.06.25
Python Learn the basics Quiz 98  (0) 2019.06.25
Python Learn the basics Quiz 97  (0) 2019.06.24