Python-Indexing- I do not understand how this bit of code is working
<p>What I do not understand is how indexing a string s = "azcbobobegghakl" would correctly give me the answer 'beggh' if I was looking for the longest substring in alphabetical order. How does this code tell the computer that 'beggh' is in alphabetical order? I thought indexing just gave each letter in the string a number that increased by one until the string ended? I tweaked the code a bit and it worked, but I do not actually understand how the code works in the first place.   </p>

<pre><code>s = "azcbobobegghakl"
longest = s[0]
current = s[0]
for c in s[1:]:
    if c &gt;= current[-1]:
        current += c
    else:
        if len(current) &gt; len(longest):
            longest = current
        current = c
print "Longest substring in alphabetical order is:", longest
</code></pre>

<p><code>&gt;=</code> compares two characters by their lexicographical order; the expression</p>

<pre><code>if c &gt;= current[-1]:
</code></pre>

<p>tests if <code>c</code> (a single character), is the same or is 'greater' than <code>current[-1]</code> (another single character. Strings are ordered lexicographically by their codepoint value; <code>a</code> is smaller than <code>b</code> because the character <code>a</code> comes before <code>b</code> in the Unicode standard:</p>

<pre><code>&gt;&gt;&gt; 'a' &gt; 'b'
False
&gt;&gt;&gt; 'a' &lt; 'b'
True
</code></pre>

<p>As such, characters are only added to <code>current</code> if they come 'later' in the alphabet than the last character of <code>current</code>. If they do not, then the sequence so far is tested for length, and a <em>new</em> substring is started from <code>c</code>.</p>

python python-3.x