본문 바로가기
프로그래밍 문제/[Python] CheckIO

CheckIO - between-markers-simplified

by UltraLowTemp-Physics 2020. 12. 5.
728x90

Problems: py.checkio.org/en/mission/between-markers-simplified/

My Solution

def between_markers(text: str, begin: str, end: str) -> str:
    """
        returns substring between two given markers
    """
    # your code here
    
    return text[text.index(begin)+1:text.index(end)]


if __name__ == '__main__':
    print('Example:')
    print(between_markers('What is >apple<', '>', '<'))

    # These "asserts" are used for self-checking and not for testing
    assert between_markers('What is >apple<', '>', '<') == "apple"
    assert between_markers('What is [apple]', '[', ']') == "apple"
    assert between_markers('What is ><', '>', '<') == ""
    assert between_markers('>apple<', '>', '<') == "apple"
    print('Wow, you are doing pretty good. Time to check it!')

 

728x90

'프로그래밍 문제 > [Python] CheckIO' 카테고리의 다른 글

[CheckIO] Right to Left  (0) 2020.12.09
CheckIO - Even the last  (0) 2020.12.08
CheckIO-sum-numbers  (0) 2020.12.07
CheckIO - correct-sentence  (0) 2020.12.06
CheckIO - Nearest value  (0) 2020.12.02

댓글