Codewars icon

Codewars 7 kyu Kata - Mumbling

By Lochard | As a newbie programmer | 29 Jul 2023


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.

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?

1


Lochard
Lochard

Asylum seeker in Lithuania. My short-lifed daily on GitHub https://github.com/locharp/asylum_daily/tree/main/en


As a newbie programmer
As a newbie programmer

Sharing entry level codes. My snippets on GitHub https://github.com/locharp/code-snippets

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.