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

[CheckIO/Scientific Expedition] striped words

by Physics 2024. 3. 24.
728x90

1. Problem: https://py.checkio.org/en/mission/striped-words/
2. My solution

import re 
def checkio(line: str) -> int:
    text = re.sub(r'[^\w\s]', " ", line)
    vowel_list = ["a", "e", "i", "o", "u", "y"]
    consonant_list = ["b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "v", "w", "x", "z"]
    number_striped_words = 0
    for dummy_text in text.split(" "):
        if dummy_text.isnumeric(): continue 
        if len(dummy_text) > 1:
            list_dummy_text = list(dummy_text.lower())

            for index in range(len(list_dummy_text)):
                if list_dummy_text[index].isnumeric()  : list_dummy_text[index] = 0
                if list_dummy_text[index] in vowel_list: list_dummy_text[index] = 1
                if list_dummy_text[index] in consonant_list: list_dummy_text[index] = -1

            Striped_words = [] 
            for index in range(len(list_dummy_text) - 1):
                Striped_words.append(list_dummy_text[index]*list_dummy_text[index+1])
            
            if (not 1 in Striped_words) and (not 0 in Striped_words): number_striped_words+=1

    return number_striped_words
728x90

댓글