영어에선 a, e, i, o, u 다섯 가지 알파벳을 모음으로 분류합니다. 문자열 my_string이 매개변수로 주어질 때 모음을 제거한 문자열을 return하도록 solution 함수를 완성해주세요.
- The replace() method replaces a specified phrase with another specified phrase.
지정된 구문을 다른 구문으로 대체 - Parameter Description
oldvalue | Required. The string to search for |
newvalue | Required. The string to replace the old value with |
count | Optional. A number specifying how many occurrences of the old value you want to replace. Default is all occurrences 반복 횟수 |
W3Schools.com
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
www.w3schools.com
def solution(my_string):
vowelList = ['a', 'e', 'i', 'o', 'u']
for vowel in vowelList:
my_string = my_string.replace(vowel, '')
return my_string
.join(), 리스트 컴프리헨션
- 컴프리헨션 문법
- 조건:
[x for x in range(1, 10+1) if x % 2 == 0]
[ x for x in range(10) if x < 5 if x % 2 == 0 ] - 반복: [ (x, y) for x in ['쌈밥', '치킨', '피자'] for y in ['사과', '아이스크림', '커피']]
- 조건:
# 기존 문법
numbers = []
for n in range(1, 10+1):
numbers.append(n)
# 컴프리헨션
[x for x in range(10)]
def solution(my_string):
vowels = 'aeiou'
return ''.join(char for char in my_string if char not in vowels)
- .join()
- ''.join(): 띄어쓰기 없이 조인
- 리스트 컴프리헨션
- for문: for char in my_string
- if문: if char not in vowels
- join 함수: ''.join(char)
https://github.com/seonmin5/codingtest_Python
GitHub - seonmin5/codingtest_Python
Contribute to seonmin5/codingtest_Python development by creating an account on GitHub.
github.com
반응형
'Python' 카테고리의 다른 글
[Python/Silver IV] 덱 - 10866, deque, split(" ") vs. split(), sys.stdin (0) | 2024.07.29 |
---|---|
[Python] 문자열 다루기 기본, .isdigit() (0) | 2024.07.20 |
[Python] 짝수 홀수 개수, answer = [0, 0], answer[n%2] +=1 (1) | 2024.07.17 |
[Python] 머쓱이 보다 키 큰 사람, .append(), .sort() - 생략 가능 (0) | 2024.07.17 |
[Python] 개미 군단, (hp//5) + ((hp%5)//3) + ((hp%5)%3) (1) | 2024.07.15 |