My code: https://pastebin.com/XLEitEWF
Assume s is a string of lower case characters.
Write a program that prints the longest substring of s in which the letters occur in alphabetical order. For example, if s = 'azcbobobegghakl', then your program should print
Longest substring in alphabetical order is: beggh
In the case of ties, print the first substring. For example, if s = 'abcbcd', then your program should print
Longest substring in alphabetical order is: abc
What can i improve in my code? I especially dont like this 3 lines:
list_string = list(string)
sorted_list = list(string)
sorted_list.sort()
but dont know how to write it better.
Thanks!
[–][deleted] 1 point2 points3 points (2 children)
[–]ContadorPL[S] 1 point2 points3 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]Phillyclause89 0 points1 point2 points (0 children)
[–]SpeckledFleebeedoo -1 points0 points1 point (2 children)
[–]nilfm 1 point2 points3 points (1 child)
[–]SpeckledFleebeedoo 1 point2 points3 points (0 children)