I've put together the following code to check if a string/word is alphabetically ordered:
def isInAlphabeticalOrder(word):
word1=sorted(word)
word2=[]
for i in word:
word2.append(i)
if word2 == word1:
return True
else:
return False
but I feel like there must be a more efficient way (fewer lines of code) to check other than turning the strings into lists. Isn't there a operand to sort strings alphabetically without turning each char into a list? Can anyone suggest a more efficient way?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…