Python Dictionary to find mirror characters in a string (original) (raw)

Last Updated : 30 Oct, 2025

Given a string and a number N, we need to mirror the characters from the N-th position to the end of the string in alphabetical order. In a mirror operation:

**Examples:

Input: N = 3, word = paradoxOutput: paizwlc

Explanation: We mirror characters from position 3 to end.

We can solve this problem in Python using the Dictionary data structure. Below are the steps:

Implementation:

Python `

def mirrorChars(input,k):

original = 'abcdefghijklmnopqrstuvwxyz'
reverse = 'zyxwvutsrqponmlkjihgfedcba'
dictChars = dict(zip(original,reverse))

prefix = input[0:k-1]
suffix = input[k-1:]
mirror = ''

for i in range(0,len(suffix)):
     mirror = mirror + dictChars[suffix[i]]
print (prefix+mirror)
     

if name == "main": input = 'paradox' k = 3 mirrorChars(input,k)

`

**Explanation: