Finding the longest substring in a string I am writing Python code to find the longest substring in a string which is an alphabetical order. I tried to minimize the number of loops to a single for loop.

Any improvements would be appreciated. Any details about the complexity of this algorithm would also be welcome, because I don't know Big-O notation all too well.

substr = '';
final_substr = '';

for index, char in enumerate(s):
    if index &lt; len(s) - 1:
        #print('Comparing %s and %s'% (char, s[index+1]));
        if ord(char) &lt;= ord(s[index + 1]):
            substr += char;
            print(substr);
        else:
            substr += char;
            if len(final_substr) &lt; len(substr):
                final_substr = substr;
            substr = '';

print('Longest substring in alphabetical order is: '+final_substr);
The algorithm has linear (\$O(n)\$) time complexity, which is good; you can't do better. It also has a linear space complexity, which is not so good; only a constant space is really required. Notice that you don't need to build substr (substr consumes memory!). It suffices to keep track of the start and end indices.
The test for index &lt; len(s) - 1 is un-pythonic. Don't ask permission, ask forgiveness.
The intention to


  minimize the number of loops


is dubious. Does it improve run time? Most likely, no (if you doubt, measure). Does it improve readability? Most likely, no. Consider the pseudocode

  while start_index &lt; string_length:
      length = scan_ordered_substring(string, start_index)
      do_business_logic
      start_index += length

I don't think that

    print(substr);


was intended.