본문 바로가기
카테고리 없음

[CheckIO] Replace Last

by UltraLowTemp-Physics 2021. 3. 10.
반응형

Problem: py.checkio.org/en/mission/replace-last/
my solution

def replace_last(line: list) -> list:
    # your code here
    if len(line) <= 1: return line
    else: return [line[-1]] + line[:-1]


if __name__ == '__main__':
    print("Example:")
    print(replace_last([2, 3, 4, 1]))

    # These "asserts" are used for self-checking and not for an auto-testing
    assert replace_last([2, 3, 4, 1]) == [1, 2, 3, 4]
    assert replace_last([1, 2, 3, 4]) == [4, 1, 2, 3]
    assert replace_last([1]) == [1]
    assert replace_last([]) == []
    print("Coding complete? Click 'Check' to earn cool rewards!")



댓글