It can be done just like
>>> x=['a','b','c'] >>> y=['a','c','b'] >>> z=['c','b','a'] >>> x==sorted(x) or x == sorted(x,reverse=True) True >>> y==sorted(x) or y == sorted(y,reverse=True) False >>> z==sorted(x) or z == sorted(z,reverse=True) True >>>
Think so. Letters are consecutive if they are sorted either ascending or descending.
As stated in the comment, since this will not work if the sequence contains holes, a different approach would be
>>> ''.join(x).lower() in string.lowercase True >>>
source share