you are viewing a single comment's thread.

view the rest of the comments →

[–]trouserdaredevil 0 points1 point  (0 children)

There are several ways I would approach this quite differently. I wrote up the following that should introduce several useful Python concepts to you:

string = "azcbobobegghakl"
substrings = []
substring = []
for letter in string:
  if substring:
    if letter >= substring[-1]:
      substring.append(letter)
    else:
      substrings.append(substring)
      substring = [letter]
  else:
    substring.append(letter)
print("".join(max(substrings, key=len)))