- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Program to find mirror characters in a string
Given a user input string and the position from that position we need to mirror the characters up to the length of the string in the alphabetical order. In this operation, we change ‘a’ to ‘z’, ‘b’ to ‘y’, 'c' to 'x', 'd' to 'w' and so on means that the first character becomes the last and so on.
Inpu t: p = 3 Input string = python Output : pygslm
Step 1: Input the string and position from we need to mirror the characters. Step 2: Creating a string which is stored in alphabetical order. Step 3: Create an empty string. Step 4: Then traverse each character up to the position from where we need a mirror and up to this sting is unchanged. Step 5: From that position up to the length of the string, we reverse the alphabetical order. Step 6: Return the string.
# Python program to find mirror characters in string def mirror(str1, n): # Creating a string having reversed # alphabetical order alphaset = "zyxwvutsrqponmlkjihgfedcba" l = len(str1) # The string up to the point specified in the # question, the string remains unchanged and # from the point up to the length of the # string, we reverse the alphabetical order result = "" for i in range(0, n): result = result + str1[i]; for i in range(n, l): result = (result + alphaset[ord(str1[i]) - ord('a')]); return result; # Driver function str1 = input("Enter the string ::>") n = int(input("Enter the position ::>")) result = mirror(str1, n - 1) print("The Result ::>",result)
Enter the string ::> python Enter the position ::> 3 The Result ::> pygslm
- Python program to find all duplicate characters in a string
- Java Program to find duplicate characters in a String?
- Program to find string after removing consecutive duplicate characters in Python
- Java program to find all duplicate characters in a string
- Java Program to Find the Duplicate Characters in a String
- Program to find length of concatenated string of unique characters in Python?
- Program to find string after deleting k consecutive duplicate characters in python
- Program to swap string characters pairwise in Python
- Find All Duplicate Characters from a String using Python
- Program to find minimum required chances to form a string with K unique characters in Python
- Python program to convert a list of characters into a string
- Python Program to Count Number of Lowercase Characters in a String
- Program to remove duplicate characters from a given string in Python
- The focal length of a spherical mirror in Python Program
- Concatenated string with uncommon characters in Python program