
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check Lowercase and Uppercase Character 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
Advertisements