Codewars note:Mumbling

"My

Exercise:

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.

 

Solutions:

1.

import itertools
def accum(s):
     return '-'.join((list(i).pop() * len(i)).title() for i in list(itertools.accumulate(s)))

2.

def accum(s):
    return '-'.join(((n * (i +1)).title()) for i,n in enumerate(s))

 3

def accum(s):
    return '-'.join(((n * (i +1)).capitalize()) for i,n in enumerate(s))

 

:itertools.accumulate()

:enumerate():

 

posted @ 2022-07-11 18:33  大序列  阅读(27)  评论(0编辑  收藏  举报