мой код для поиска самой длинной подстроки в алфавитном порядке, используя python
что я подразумеваю под самой длинной подстрокой в алфавитном порядке?если входное значение было «asdefvbrrfqrstuvwxffvd», выходное значение будет «qrstuvwx»
#we well use the strings as arrays so don't be confused
s='abcbcd'
#give spaces which will be our deadlines
h=s+' (many spaces) '
#creat outputs
g=''
g2=''
#list of alphapets
abc='abcdefghijklmnopqrstuvwxyz'
#create the location of x"the character the we examine" and its limit
limit=len(s)
#start from 1 becouse we substract one in the rest of the code
x=1
while (x<limit):
#y is the curser that we will move the abc array on it
y=0
#putting our break condition first
if ((h[x]==' ') or (h[x-1]==' ')):
break
for y in range(0,26):
#for the second character x=1
if ((h[x]==abc[y]) and (h[x-1]==abc[y-1]) and (x==1)):
g=g+abc[y-1]+abc[y]
x+=1
#for the third to the last character x>1
if ((h[x]==abc[y]) and (h[x-1]==abc[y-1]) and (x!=1)):
g=g+abc[y]
x+=1
if (h[x]==' '):
break
print ("Longest substring in alphabetical order is:" +g )
, оно не заканчивается, как если бы оно находилось в бесконечном цикле, что мне делать?Я новичок, поэтому я хочу, чтобы с циклами for, а не функциями из библиотек. Заранее спасибо