반응형
Description:
Remove an exclamation mark from the end of a string. For a beginner kata, you can assume that the input data is always a string, no need to verify it.
Examples
remove("Hi!") == "Hi"
remove("Hi!!!") == "Hi!!"
remove("!Hi") == "!Hi"
remove("!Hi!") == "!Hi"
remove("Hi! Hi!") == "Hi! Hi"
remove("Hi") == "Hi"
Solution:
def remove(s):
if a := s and s[-1] == "!": ...
return a and s[:-a] or s
반응형
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
1215. Is it even? (0) | 2022.12.15 |
---|---|
1214. Find the position! (0) | 2022.12.14 |
1212. String cleaning (0) | 2022.12.12 |
1211. Maximum Product (0) | 2022.12.11 |
1210. Bumps in the Road (0) | 2022.12.11 |