VOOZH about

URL: https://www.geeksforgeeks.org/python/python-dictionary-find-mirror-characters-string/

⇱ Python Dictionary to find mirror characters in a string - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Python Dictionary to find mirror characters in a string

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:

  • 'a' becomes 'z'
  • 'b' becomes 'y'
  • 'c' becomes 'x', and so on.

Examples: 

Input: N = 3, word = paradox Output: 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:

  • The mirror value of 'a' is 'z', 'b' is 'y', etc.
  • Create a dictionary mapping each character to its mirror value.
  • Traverse characters from position N to the end of the string and replace them using the dictionary.
  • Concatenate the unchanged prefix (first N-1 characters) with the mirrored part.

Implementation:


Output
paizwlc

Explanation:

  • dict(zip(original, reverse)): creates a dictionary mapping each letter to its mirror.
  • prefix = input[0:k-1]: first k-1 characters, unchanged.
  • suffix = input[k-1:]: characters from position k onward, to be mirrored.
  • input[0:k-1]: first k-1 characters, unchanged.
  • input[k-1:]: characters from position k onward, to be mirrored.

Related Articles:

Comment