Replace Duplicate String Characters
<p>I need to convert a string <code>word</code> where each character that appears only once should be appear as <code>'('</code> in the new string. Any duplicate characters in the original string should be replaced with <code>')'</code>. </p>

<p>My code below...</p>

<pre><code>def duplicate_encode(word):
new_word = ''
for char in word:
    if len(char) &gt; 1:
        new_word += ')'
    else:
        new_word += '('
return new_word
</code></pre>

<p>The test I'm not passing is as follows: </p>

<p>'((((((' should equal '()()()'</p>

<p>This would suggest that, if for example, the input is "recede," the output should read <code>()()()</code>. </p>

<p>Just because (it's late and) it's possible:</p>

<pre><code>def duplicate_encode(word):

    return (lambda w: ''.join(('(', ')')[c in w[:i] + w[i+1:]] for i, c in enumerate(w)))(word.lower())

print(duplicate_encode("rEcede"))
</code></pre>

<p>OUTPUT</p>

<pre><code>&gt; python3 test.py
()()()
&gt;
</code></pre>

python string replace duplicates iteration