
- 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 lowercase and uppercase characters are in same order in Python
Suppose we have a string s with only lowercase or uppercase letters not numbers. We have to check whether both lowercase and uppercase letters follow the same order respectively or not. So, if a letter occurs more than once in lowercase then the occurrence of the same character in the uppercase will be same.
So, if the input is like s = "piPpIePE", then the output will be True, as occurrences of lowercase letters and uppercase letters are same, and they are in the same order in lowercase and uppercase also.
To solve this, we will follow these steps −
- lowercase := blank string, uppercase := blank string
- for i in range 0 to size of s - 1, do
- if s[i] is uppercase letter, then
- uppercase := uppercase concatenate s[i]
- otherwise,
- lowercase := lowercase concatenate s[i]
- if s[i] is uppercase letter, then
- to_upper := convert lowercase to uppercase
- return true when to_upper is same as uppercase otherwise false
Example
Let us see the following implementation to get better understanding −
def solve(s) : lowercase = "" uppercase = "" for i in range(len(s)) : if ord(s[i]) >= 65 and ord(s[i]) <= 91 : uppercase += s[i] else : lowercase += s[i] to_upper = lowercase.upper() return to_upper == uppercase s = "piPpIePE" print(solve(s))
Input
"piPpIePE"
Output
True
- Related Articles
- Check if the characters of a given string are in alphabetical order in Python
- Converting Odd and Even-indexed characters in a string to uppercase/lowercase in JavaScript?
- Golang Program to convert Uppercase to Lowercase characters, using binary operator.
- Replacing upperCase and LowerCase in a string - JavaScript
- Java program to find the percentage of uppercase, lowercase, digits and special characters in a String
- How to check whether a string is in lowercase or uppercase in R?
- How to convert lowercase letters in string to uppercase in Python?
- Program to check string is palindrome with lowercase characters or not in Python
- Check if frequency of characters are in Recaman Series in Python
- Check if both halves of the string have same set of characters in Python
- Check if frequency of all characters can become same by one removal in Python
- How to convert all uppercase letters in string to lowercase in Python?
- 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
- Count spaces, uppercase and lowercase in a sentence using C

Advertisements