I'm trying to write a function that checks wether or not the characters in a string are sorted using recursion. This is what I came up with:
def is_sorted(x,i):
if i >= len(x):
return True
elif x[i] <= x[i-1]:
return False
else:
is_sorted(x,i+1)
I used these to test my function:
x = "abcadef"
y = "aabcdef"
z = "abcdef"
print is_sorted(x, 1)
print is_sorted(y, 1)
print is_sorted(z, 1)
I expected to get False, False, True, but instead I got None, False, None. Why? :(