Checking if a string's characters are ascending alphabetically and its ascent is evenly spaced python
- by FRU5TR8EDD
So need to check if a string's characters are ascending alphabetically and if that ascent is evenly spaced.
a = "abc"
b = "ceg"
So a is alphabetically ascending and it's spacing is 1 (if you convert to the ordinal values they are 97,98,99). And b is also alphabetically ascending and it's spacing is 2 (99,101,103).
And I am sticking with the following code:
a = 'jubjub'
words1 = []
ords = [ord(letter) for letter in a]
diff = ords[1] - ords[0]
for ord_val in range(1, len(ords)-1):
if diff > 0:
if ords[ord_val + 1] - ords[ord_val] == diff:
if a not in words1:
words1.append((a, diff))
print words1
How come 'jubjub' works, 'ace' works, but 'catcat' doesn't?