Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. temp = ''
  2. results = []
  3. for i in range(len(s)):
  4. if temp == '':
  5. temp = s[i]
  6. else:
  7. if temp[-1] <= s[i]:
  8. temp += s[i]
  9. else:
  10. temp += s[i-1]
  11. results.append(temp)
  12. temp = ''
  13. if not results:
  14. results.append(temp)
  15. print("Longest substring in alphabetical order is: " + results[0])
  16. else:
  17. print("Longest substring in alphabetical order is: " + max(results, key=len))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement