remove certain consecutive duplicates in a string?
<p>I want to define a function that takes a string and a letter in that string and outputs a new string with the occurrences of the letter being once. For example </p>

<pre><code>my_function("happy kitten","p")
'hapy kitten' 
</code></pre>

<p>or     </p>

<pre><code>my_function("happykitten","t") 
'happykiten'
</code></pre>

<p>I've tried </p>

<pre><code>def my_function(string, lett):
newString = ""
for char in string: #all characters
    for s in string: #character I'm testing
        if s == len(s) &gt; 1: 
            newString+=lett # if there are multiple occurrences of s, replace with lett since its a single char anyway
        else:
            newString+=char #if not a duplicate, add next char to newString
    return newString #("happy kitten","p") returns 'ppppppppppp'
</code></pre>

<p>and </p>

<pre><code>def my_function(string, lett):
newString = ""
for char in string: #all characters
    for s in string: #character I'm testing
        if s == s+1: 
            newString+=lett # if there are multiple occurrences of s, replace with lett since its a single char anyway
        else:
            newString+=char #if not a duplicate, add next char to newString
    return newString #TypeError: cannot concatenate 'str' and 'int' objects
</code></pre>

<p>What't going wrong in my functions? Please no imports or built-in functions.</p>
