#!/usr/bin/env python3 """ s = a string. ------------------------------------------------------------------------ Takes a string and determines the first longest substring in alphabetical order within it, then returns this substring. """ __author__ = 'Chauncy Kent' __copyright__ = 'Copyright 2023, Chauncy Kent' __credits__ = ['Chauncy Kent'] __license__ = 'GNU GPLv3' __version__ = '1.0' __maintainer__ = 'Chauncy Kent' __email__ = 'ChauncyJKent@gmail.com' __status__ = 'Production' #------------------------------------------------------------------------------ def longest_alpha_substring(s): #Initializes an instance of the function longest = "" Max ="" if(len(s) == 1): longest = s for i in range(len(s) -1): if s[i] <= s[i + 1]: longest = longest + s[i] if(i==len(s) -2): longest = longest + s[i + 1] else: longest = longest + s[i] if len(longest) > len(Max): Max = longest longest = "" else: longest = "" if(len(longest) > len(Max)): print("Longest substring in alphabetical order is: " + longest) else: print("Longest substring in alphabetical order is: " + Max) #------------------------------------------------------------------------------ if __name__ == '__main__': longest_alpha_substring('So long, and thanks for all the fish!')