본문 바로가기

Python_Matter/Solve

Python Learn the basics Quiz 81

반응형

Q>

Assuming you are developing a user based system like facebook, you will want to provide the functionality to search for other members regardless of the presence of accents in a username.

(페이스 북과 같은 사용자 기반 시스템을 개발 중이라고 가정하면 사용자 이름에 액센트가 있는지 여부에 관계없이 다른 회원을 검색하는 기능을 제공하는 것이 좋습니다.)

Without using 3rd party collation library, you will need to remove the accents from username before comparison.

(타사 데이터 정렬 라이브러리를 사용하지 않고 비교하기 전에 사용자 이름에서 악센트를 제거해야합니다.)

é - letter with accent; e - letter without accent; ̀ and ́ - stand alone accents;

(é - 억양이있는 글자; 악센트없는 전자 편지; 그리고 - 독창적 인 강세;)

 

Input: A phrase as a string (unicode)

         (문자열 (유니 코드)로 된 구.)

 

Output: An accent free Unicode string.

           (악센트가없는 유니 코드 문자열입니다.)

 

Example:

checkio(u"préfèrent") == u"preferent"
checkio(u"loài trăn lớn") == u"loai tran lon"

 

How it is used: It might be a part username verification process or system that propose username based on first and last name of user

(사용자의 성과 이름을 기반으로 사용자 이름을 제안하는 부분 사용자 이름 확인 프로세스 또는 시스템 일 수 있습니다.)

 

Precondition: 0≤|input|≤40

 

A>

'''
unicodedata : 유니코드 문자에 대한 문자 속성을 정의하는 유니코드 문자 데이터베이스(UCD -- Unicode Character Database)에
대한 액세스를 제공
https://python.flowdas.com/library/unicodedata.html
'''
import unicodedata

def checkio(in_string):
    "remove accents"
    '''
    unicodedata.normalize(form, unistr) : 유니코드 문자열 unistr에 대한 정규화 형식(normal form) form을 반환
    unicodedata.category(chr) : chr 문자에 할당된 일반 범주(general category)를 문자열로 반환
    '''
    return ''.join((c for c in unicodedata.normalize('NFD', in_string) if unicodedata.category(c) != 'Mn'))
    # These "asserts" using only for self-checking and not necessary for auto-testing


if __name__ == '__main__':
    assert checkio(u"préfèrent") == u"preferent"
    assert checkio(u"loài trăn lớn") == u"loai tran lon"
    print('Done')

 

O>

Done

Process finished with exit code 0

 

S>

https://py.checkio.org

반응형

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

Python Learn the basics Quiz 83  (0) 2019.06.21
Python Learn the basics Quiz 82  (0) 2019.06.21
Python Learn the basics Quiz 80  (0) 2019.06.20
Python Learn the basics Quiz 79  (0) 2019.06.20
Python Learn the basics Quiz 78  (0) 2019.06.20