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

[CheckIO] Goes Right After

by UltraLowTemp-Physics 2021. 12. 3.
728x90

[1] Problem: https://py.checkio.org/en/mission/goes-after/

[2] My solution 

def goes_after(word: str, first: str, second: str) -> bool:
    # your code here
    
    word_list = list(word)
    if (first not in word_list) or (second not in word_list): return False
    if first == second: return False
    
    first_index = word_list.index(first)
    word_list.pop(first_index)
    second_index = word_list.index(second)
    
    if first_index == second_index: return True
    else: return False

 

[3] Best Solutions

def goes_after(word: str, first: str, second: str) -> bool:
    try:
        return word.index(second)-word.index(first) == 1
    except ValueError:
        return False
728x90

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

[Check-IO] Sum by Type  (0) 2021.12.12
[Check-IO] Time converter  (0) 2021.12.10
[Check-IO] Absolute Sorting  (0) 2021.11.14
[Check-IO] Frequency Sorting  (0) 2021.04.18
[CheckIO] Median  (0) 2021.03.23

댓글