Exercise 9.6. Write a function called is_abecedarian that returns True if the letters in a word
appear in alphabetical order (double letters are ok). How many abecedarian words are there?
def isa(word):
nw = word.casefold()
count = 0
pos = 0
for letter in nw:
if ord(letter) < pos:
return False
elif ord(letter) > pos:
pos = ord(letter)
count = 0
else:
count = count+1
if count > 1:
return False
return True
print('abbc', isa('abbc'))
print('abbbc', isa('abbbc'))
print('abba', isa('abba'))
fin = open('words.txt')
count = 0
for line in fin:
if isa(line.strip()):
count = count+1
print(count, '个单词的字母是按字母表顺序排列的')