When executing my code for the given task, I keep getting the longest string plus the next letter in the iteration. For example, if I use
s = \'azcbobobeggh
You've got a couple items to address. The first is that when you use...
final = result
This is not just assigning the values in result to final. It points the variable 'final' to the memory address containing the list that 'result' is also pointing to. So then if result is changed, so is final. To assign the values in result, use...
final = result[:]
which will give you the values of a slice of the list from beginning to end. Or you can use...
final = list(result)
After that change, you'll need to remove the length comparison in your elif statement.
Edited code:
s = 'azcbobobegghakl'
result = []
final = []
for letters in s:
result += letters
if result == sorted(result) and len(result) >= len(final):
final = list(result)
elif result != sorted(result):
result = [result[len(result)-1]]
print "".join(final)