취미생활/CheckIO

[checkIO]Element 02.Easy Unpack

우주먼지의하루 2020. 2. 22. 11:25
728x90

our mission here is to create a function that gets a tuple and returns a tuple with 3 elements - the first, third and second to the last for the given array.

Input: A tuple, at least 3 elements long.

Output: A tuple.

Example:

easy_unpack((1, 2, 3, 4, 5, 6, 7, 9)) == (1, 3, 7)

easy_unpack((1, 1, 1, 1)) == (1, 1, 1)

easy_unpack((6, 3, 7)) == (6, 7, 3)

 

* 튜플에서 첫번째, 세번째 그리고 뒤에서 두번째 값을 output

 

- 풀이

 

def easy_unpack(elements: tuple) -> tuple:
    n_list = []
    n_list.append(elements[0])
    n_list.append(elements[2])
    n_list.append(elements[len(elements)-2])
    
    result = tuple(n_list)
    
    return result

 

- 다른 풀이

 

def easy_unpack(elements: tuple) -> tuple:
    """
        returns a tuple with 3 elements - first, third and second to the last
    """
    x=elements[0]
    y=elements[2]
    z=elements[-2]
    return (x,y,z)
반응형

'취미생활 > CheckIO' 카테고리의 다른 글

[checkIO]Element 04.Digits Multiplication  (0) 2020.02.26
[checkIO]Element 03.Index Power  (0) 2020.02.24
[checkIO]Element 01.Say Hi  (0) 2020.02.21
[checkIO]Home 12.Xs and Os Referee  (0) 2020.02.19
[checkIO]Home 11.Bird Language  (0) 2020.02.17