모음 제거 & 중복된 문자 제거(programmers Lv0)

송성원·2023년 12월 16일
1

programmers

목록 보기
5/9
post-thumbnail

모음제거

# 모음제거( join함수를 통해 vowels에 포함되지 않으면 ''에 추가된다. )

def solution(my_string):
    vowels = "aeiou"
    result = ''.join(char for char in my_string if char not in vowels)
    return result

딱히 어렵지는 않은 수준, 간결하게 잘 풀었다....





중복된 문자 제거

# 중복된 문자 제거

def solution(my_string):
    

    unique_chars = "".join(sorted(set(my_string), key=my_string.index))

    return unique_chars

join함수에는(value, key) 여기서 value는 앞의 함수가 쓰여진 부분에 합류하고
key부분은 key 함수를 호출하여 그 결과에 따라 정렬을 수행한다.

profile
개발에 도전하는 문과생입니다.

0개의 댓글