반응형
In this Kata, you will be given a string that may have mixed uppercase and lowercase letters and your task is to convert that string to either lowercase only or uppercase only based on:
- make as few changes as possible.
- if the string contains equal number of uppercase and lowercase letters, convert the string to lowercase.
For example:
solve("coDe") = "code". Lowercase characters > uppercase. Change only the "D" to lowercase.
solve("CODe") = "CODE". Uppercase characters > lowecase. Change only the "e" to uppercase.
solve("coDE") = "code". Upper == lowercase. Change all to lowercase.
More examples in test cases. Good luck!
Solution:
def solve(s):
return sum([i.islower() for i in s]) >= len(s)/2 and s.lower() or s.upper()
반응형
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
Remove anchor from URL (0) | 2022.08.09 |
---|---|
Find the unique number (0) | 2022.08.08 |
Factorial (0) | 2022.08.07 |
Count the Digit (0) | 2022.08.05 |
Descending Order (0) | 2022.08.05 |