
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Check if the characters of a given string are in alphabetical order in Python
Suppose we have a string s. We have to check whether characters in s are in alphabetical order or not.
So, if the input is like s = "mnnooop", then the output will be True.
To solve this, we will follow these steps −
- char_arr := a new list from the characters present in s
- sort the list char_arr
- return char_arr is same as list of all characters in s then true otherwise false
Let us see the following implementation to get better understanding −
Example Code
def solve(s): char_arr = list(s) char_arr.sort() return char_arr == list(s) s = "mnnooop" print(solve(s))
Input
"mnnooop"
Output
True
- Related Articles
- Check whether the vowels in a string are in alphabetical order or not in Python
- Removing n characters from a string in alphabetical order in JavaScript
- Python - Check If All the Characters in a String Are Alphanumeric?
- Check if string follows order of characters defined by a pattern or not in Python
- Check if lowercase and uppercase characters are in same order in Python
- Python code to print common characters of two Strings in alphabetical order
- Python - Check if frequencies of all characters of a string are different
- Check if characters of a given string can be rearranged to form a palindrome in Python
- Java program to check order of characters in string
- Remove all non-alphabetical characters of a String in Java?
- Print common characters of two Strings in alphabetical order in C++
- Sum of the alphabetical values of the characters of a string in C++
- Check if a given string is made up of two alternating characters in C++
- Check if frequency of characters are in Recaman Series in Python
- Java code to print common characters of two Strings in alphabetical order

Advertisements