반응형
Description:
This time no story, no theory. The examples below show you how to write function accum:
Examples:
accum("abcd") -> "A-Bb-Ccc-Dddd"
accum("RqaEzty") -> "R-Qq-Aaa-Eeee-Zzzzz-Tttttt-Yyyyyyy"
accum("cwAt") -> "C-Ww-Aaa-Tttt"
The parameter of accum is a string which includes only letters from a..z and A..Z.
Solution:
1. Extract each character from a string with an index.
2. Characters are divided into uppercase and lowercase letters, and lowercase letters are added by the number of indexes.
3. After merging the letters, one string is returned by adding '-' between them.
def accum(s):
return '-'.join([v.upper()+(v.lower()*i) for i, v in enumerate(s)])
반응형
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
Sort array by string length (0) | 2022.04.29 |
---|---|
Sum of odd numbers (0) | 2022.04.28 |
Two to One (0) | 2022.04.26 |
Apparently-Modifying Strings (0) | 2022.04.26 |
The Office I - Outed (0) | 2022.04.24 |