본문 바로가기

Python_Matter/Solve

Python Learn the basics Quiz 88

반응형

Q>

For language training our Robots want to learn about suffixes.

(언어 훈련을 위해 로봇은 접미사에 대해 배우고 싶습니다.)

In this task, you are given a set of words in lower case.

(이 작업에서는 소문자로 된 단어 집합이 제공됩니다.)

Check whether there is a pair of words, such that one word is the end of another (a suffix of another).

(한 단어가 다른 단어의 끝 (다른 접미사)과 같은 단어 쌍이 있는지 확인하십시오.)

For example: {"hi", "hello", "lo"} -- "lo" is the end of "hello", so the result is True.

(예 : { "hi", "hello", "lo"} - "lo"는 "hello"의 끝이므로 결과는 True입니다.)

 

Input: Words as a set of strings.

        (단어 집합을 문자열로 사용합니다.)

 

Output: True or False, as a boolean.

           (True 또는 False를 부울 값으로 사용합니다.)

 

Example:

checkio({"hello", "lo", "he"}) == True
checkio({"hello", "la", "hellow", "cow"}) == False
checkio({"walk", "duckwalk"}) == True
checkio({"one"}) == False
checkio({"helicopter", "li", "he"}) == False

 

A>

def checkio(words_set):
    for w1 in words_set:
        for w2 in words_set:
            # endswith : 문자열 안에서 특정 텍스트를 찾는 메소드(맨끝에서)
            if not(w1 == w2) and (w1.endswith(w2)):
                return True

    return False

#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
    print("Example:")
    print(checkio({"hello", "lo", "he"}))

    assert checkio({"hello", "lo", "he"}) == True, "helLO"
    assert checkio({"hello", "la", "hellow", "cow"}) == False, "hellow la cow"
    assert checkio({"walk", "duckwalk"}) == True, "duck to walk"
    assert checkio({"one"}) == False, "Only One"
    assert checkio({"helicopter", "li", "he"}) == False, "Only end"
    print("Done! Time to check!")

 

O>

Example:
True
Done! Time to check!

Process finished with exit code 0

 

S>

https://py.checkio.org/

반응형

'Python_Matter > Solve' 카테고리의 다른 글

Python Learn the basics Quiz 90  (0) 2019.06.21
Python Learn the basics Quiz 89  (0) 2019.06.21
Python Learn the basics Quiz 87  (0) 2019.06.21
Python Learn the basics Quiz 86  (0) 2019.06.21
Python Learn the basics Quiz 85  (0) 2019.06.21