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>The expression <code>c &gt;= current[-1]</code> lexicographically compares each character with its predecessor in the string. More simply:</p>

<pre><code>&gt;&gt;&gt; 'a' &gt;= 'a'
True
&gt;&gt;&gt; 'b' &gt;= 'a'
True
&gt;&gt;&gt; 'b' &gt;= 'c'
False
&gt;&gt;&gt; 'z' &gt;= 'a'
True
</code></pre>

<p>So all the code is doing is to accumulate runs of characters that have each character <code>&gt;=</code> the last one, and to keep the longest one seen.</p>

python python-3.x