Codewars icon

Codewars 7 kyu Kata - Mumbling

By Lochard | As a newbie programmer | 29 Jul 2023


This time no story, no theory. The examples below show you how to write function accum:



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.

def accum( s ):
    ans = ""
    for i in range( len( s ) ):
        ans += ( s[i] * ( i + 1 ) ).title() + "-"
    return ans[:-1]

How do you rate this article?



Asylum seeker in Lithuania. My short-lifed daily on GitHub

As a newbie programmer
As a newbie programmer

Sharing entry level codes. My snippets on GitHub

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.