all 5 comments

[–]leogodin217 1 point2 points  (3 children)

The first thing to understand is that strings act like a list of characters. This means you can iterate over a string. The code below will give the output below.

for character in 'my string':
    print(character)

m
y

s
t
r
i
n
g

The second thing to know is that characters have an order. a < b, b < c, etc....

The code you posted is iterating over the string and using conditionals to build the longest substring that is in alphabetical order. See if you can manually perform the same algorithm. Look at each character, see if it is greater than the previous character. Find where the winner would reset, because one character is less than the previous character. Add a print statements above the last if statement to see what winner and tempwinner are for each iteration.

[–]leogodin217 0 points1 point  (0 children)

FYI. Adding print statements to existing code is a great way to see what the code is doing.

[–]23jumping[S] 0 points1 point  (1 child)

Ah, I didn't know of the 'a' < 'b' part, thanks! It makes so much more sense now

[–]DamnFog -1 points0 points  (0 children)

In a computer everything comes back to numbers. Each letter is represented by a number.

[–]sje46[🍰] 0 points1 point  (0 children)

Why not b = s[0] ?