Repeating characters results in wrong repetition counts
<p>My function looks like this:</p>

<pre><code>def accum(s):
    a = []
    for i in s:
        b = s.index(i)
        a.append(i * (b+1))
    x = "-".join(a)
    return x.title()
</code></pre>

<p>with the expected input of:</p>

<pre><code>'abcd'
</code></pre>

<p>the output should be and is:</p>

<pre><code>'A-Bb-Ccc-Dddd' 
</code></pre>

<p>but if the input has a recurring character:</p>

<pre><code>'abccba'
</code></pre>

<p>it returns:</p>

<pre><code>'A-Bb-Ccc-Ccc-Bb-A'
</code></pre>

<p>instead of:</p>

<pre><code>'A-Bb-Ccc-Cccc-Bbbbb-Aaaaaa'
</code></pre>

<p>how can I fix this?</p>

<p>This is because <code>s.index(a)</code> returns the first index of the character. You can use <code>enumerate</code> to pair elements to their indices:</p>

<p>Here is a Pythonic solution:</p>

<pre><code>def accum(s):
    return "-".join(c*(i+1) for i, c in enumerate(s)).title()
</code></pre>

python