daco2020 2022. 4. 27. 22:17

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)])