나는 이렇게 학습한다/Algorithm & SQL

Simple Fun #176: Reverse Letter

daco2020 2022. 7. 27. 19:37
반응형

Task

Given a string str, reverse it and omit all non-alphabetic characters.

Example

For str = "krishan", the output should be "nahsirk".

For str = "ultr53o?n", the output should be "nortlu".

Input/Output

  • [input] string str

A string consists of lowercase latin letters, digits and symbols.

  • [output] a string

 

Solution:

def reverse_letter(string):
    return ''.join([char for char in string[::-1] if char.isalpha()])

 

Other Solution:

def reverse_letter(string):
    return ''.join(filter(str.isalpha, reversed(string)))

 

반응형

'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글

Build Tower  (0) 2022.07.29
Highest Scoring Word  (0) 2022.07.28
Money, Money, Money  (0) 2022.07.26
Calculate BMI  (0) 2022.07.25
Check the exam  (0) 2022.07.24