본문 바로가기

Python_Matter/Solve

Python Learn the basics Quiz 65

반응형

Q>

Let's continue examining words.

(단어를 계속해서 살펴 봅시다.)

You are given two string with words separated by commas.

(단어가 쉼표로 구분 된 두 개의 문자열이 제공됩니다.)

Try to find what is common between these strings.

(이 문자열들 사이에 공통점이 있는지 찾으십시오.)

The words are not repeated in the same string.

(단어는 동일한 문자열에서 반복되지 않습니다.)

Your function should find all of the words that appear in both strings.

(함수는 두 문자열에 나타나는 모든 단어를 찾아야합니다.)

The result must be represented as a string of words separated by commas in alphabetic order.

(결과는 알파벳순으로 쉼표로 구분 된 일련의 단어로 표현되어야합니다.)

 

Input: Two arguments as strings.

         (두 개의 인수가 문자열입니다.)

 

Output: The common words as a string.

           (일반적인 단어를 문자열로 사용합니다.)

 

Example:

checkio("hello,world", "hello,earth") == "hello"
checkio("one,two,three", "four,five,six") == ""
checkio("one,two,three", "four,five,one,two,six,three") == "one,three,two"

 

How it is used: Here you can learn how to work with strings and sets.

                     (문자열 및 세트 작업 방법을 배울 수 있습니다.)

                     This knowledge can be useful for linguistic analysis.

                     (이 지식은 언어 분석에 유용 할 수 있습니다.)

 

Precondition: Each string contains no more than 10 words.

                   (각 문자열은 10 단어를 초과하지 않습니다.)

                   All words separated by commas.

                   (모든 단어는 쉼표로 구분됩니다.)
                   All words consist of lowercase latin letters.

                   (모든 단어는 소문자 라틴 문자로 구성됩니다.)

 

A>

def checkio(first, second):
    # set : 교집합이나 합집합을 구할 수 있음.
    # split
    first_set = set(first.split(','))
    second_set = set(second.split(','))
    # intersection : 교집합
    common = first_set.intersection(second_set)

    # 콤마를 기준으로 합치기
    return ',' .join(sorted(common))

#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
    assert checkio("hello,world", "hello,earth") == "hello", "Hello"
    assert checkio("one,two,three", "four,five,six") == "", "Too different"
    assert checkio("one,two,three", "four,five,one,two,six,three") == "one,three,two", "1 2 3"

 

O>


Process finished with exit code 0

 

S>

https://py.checkio.org

반응형

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

Python Learn the basics Quiz 67  (0) 2019.06.14
Python Learn the basics Quiz 66  (0) 2019.06.14
Python Learn the basics Quiz 64  (0) 2019.06.14
Python Learn the basics Quiz 63  (0) 2019.06.14
Python Learn the basics Quiz 62  (0) 2019.06.14