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>You should use Unicode strings.  Byte strings in UTF-8 use a variable number of bytes per character.  Unicode use one (at least those in the BMP on Python 2...the first 65536 characters):</p>

<pre><code>#coding:utf8
s = u"××§×××"
t = u'&lt;b&gt;'+s[0]+u'&lt;/b&gt;'+s[1:]
print(t)
with open('out.htm','w',encoding='utf-8-sig') as f:
    f.write(t)
</code></pre>

<p>Output:</p>

<pre><code>&lt;b&gt;×&lt;/b&gt;×§×××
</code></pre>

<p>But my Chrome browser displays <code>out.htm</code> as:</p>

<p><a href="http://i.stack.imgur.com/kJSju.png" rel="nofollow"><img src="http://i.stack.imgur.com/kJSju.png" alt="enter image description here"></a></p>

python unicode python-2.x