Oct-05-2017, 06:08 PM
I have to write a function that takes a string argument str, returns the longest substring of str in which the
letters occur in alphabetical order. For example if the string is 'azcbobobegghakl', then the function
should return 'beggh' In the case of ties, print the rst substring. For example, if s = 'abcbcd', then the
function should return 'abc'.
I wrote this so far, this only returns True if there is a substring inside a string:
letters occur in alphabetical order. For example if the string is 'azcbobobegghakl', then the function
should return 'beggh' In the case of ties, print the rst substring. For example, if s = 'abcbcd', then the
function should return 'abc'.
I wrote this so far, this only returns True if there is a substring inside a string:
import sys #s1 is the small string, s2 is the bigger string, and k is the index s1 = sys.argv[1] s2= sys.argv[2] k = 0 #k=0, same as the first index of a list with the index 0 def substring(s1, s2, k): #len stands for length, which is the number of characters in a word if s1 in s2[k:]: #this function finds the substring s1 in s2 return True return False print(substring(s1,s2,k)) #Prints out the presence of s1 in s2 (boolean value)