Program to check string is palindrome with lowercase characters or not in Python

PythonServer Side ProgrammingProgramming

Suppose we have alphanumeric string s. It can hold both uppercase or lowercase letters. We have to check whether s is a palindrome or not considering only the lowercase alphabet characters.

So, if the input is like s = "rLacHEec0a2r8", then the output will be True because the string contains "racecar" in lowercase, which is a palindrome.

To solve this, we will follow these steps −

  • x := blank string

  • for each character i in s, do

    • if i is in lowercase, then

      • x := x concatenate i

  • return true when x is palindrome, otherwise false

Example

Let us see the following implementation to get better understanding

def solve(s):
   x = ""
   for i in s:
      if i.islower():
         x += i

   return x == x[::-1]

s = "rLacHEec0a2r8"
print(solve(s))

Input

"rLacHEec0a2r8"

Output

True
raja
Updated on 12-Oct-2021 11:27:36

Advertisements