Python: Correct Way to refer to index of unicode string
<p>Not sure if this is exactly the problem, but I'm trying to insert a  tag on the first letter of a unicode string and it seems that this is not working. Could these be because unicode indices work differently than those of regular strings?</p>

<p>Right now my code is this:</p>

<pre><code>for index, paragraph in enumerate(intro[2:-2]):
    intro[index] = bold_letters(paragraph, 1)

def bold_letters(string, index):
    return "&lt;b&gt;"+string[0]+"&lt;/b&gt;"+string[index:]
</code></pre>

<p>And I'm getting output like this:</p>

<pre><code>&lt;b&gt;?&lt;/b&gt;?×¨× ×××× ×××©×ª×× ××××¨× ×××××ª× ××¨×¦×× × ×× ×¦×× ××©××× ××¨×¥ ××××× ××× ××××× ××. 
</code></pre>

<p>It seems the unicode gets messed up when I try to insert the HTML tag. I tried messing with the insert position but didn't make any progress.</p>

<p>Example desired output (hebrew goes right to left):</p>

<pre><code>&gt;&gt;&gt;first_letter_bold("××§×××")
"××§××&lt;\b&gt;×&lt;b&gt;"
</code></pre>

<p>BTW, this is for Python 2</p>

<p>The behavior you're seeing suggests you have a byte string instead of a unicode string - your code should work if it was a unicode string, unicode string indexes work the same way as 'normal' ascii strings. In python 3, at least.</p>

python unicode python-2.x