Python Dictionary to find mirror characters in a string Last Updated : 28 Jul, 2022 Comments Improve Suggest changes Like Article Like Report Given a string and a number N, we need to mirror the characters from the N-th position up to the length of the string in alphabetical order. In mirror operation, we change ‘a’ to ‘z’, ‘b’ to ‘y’, and so on. Examples: Input : N = 3 paradox Output : paizwlc We mirror characters from position 3 to end. Input : N = 6 pneumonia Output : pneumlmrz We have an existing solution for this problem please refer to Mirror characters of a string link. We can solve this problem in Python using Dictionary Data Structure. The mirror value of 'a' is 'z','b' is 'y', etc, so we create a dictionary data structure and one-to-one map reverse sequence of alphabets onto the original sequence of alphabets. Now traverse characters from length k in given string and change characters into their mirror value using a dictionary. Implementation: Python3 # function to mirror characters of a string def mirrorChars(input,k): # create dictionary original = 'abcdefghijklmnopqrstuvwxyz' reverse = 'zyxwvutsrqponmlkjihgfedcba' dictChars = dict(zip(original,reverse)) # separate out string after length k to change # characters in mirror prefix = input[0:k-1] suffix = input[k-1:] mirror = '' # change into mirror for i in range(0,len(suffix)): mirror = mirror + dictChars[suffix[i]] # concat prefix and mirrored part print (prefix+mirror) # Driver program if __name__ == "__main__": input = 'paradox' k = 3 mirrorChars(input,k) Outputpaizwlc Time complexity: O(n)Auxiliary Space: O(n) Comment More infoAdvertise with us Next Article Python Dictionary to find mirror characters in a string S Shashank Mishra Follow Improve Article Tags : Strings Python DSA python-dict Python dictionary-programs +1 More Practice Tags : pythonpython-dictStrings Similar Reads Find all duplicate characters in string in Python In this article, we will explore various methods to find all duplicate characters in string. The simplest approach is by using a loop with dictionary.Using Loop with DictionaryWe can use a for loop to find duplicate characters efficiently. First we count the occurrences of each character by iteratin 2 min read How to Find Chinese And Japanese Character in a String in Python Detecting Chinese or Japanese characters in a string can be useful for a variety of applications, such as text preprocessing, language detection, and character classification. In this article, weâll explore simple yet effective ways to identify Chinese or Japanese characters in a string using Python 5 min read Python | Count the Number of matching characters in a pair of string The problem is about finding how many characters are the same in two strings. We compare the strings and count the common characters between them. In this article, we'll look at different ways to solve this problem.Using Set Sets are collections of unique items, so by converting both strings into se 2 min read Mirror characters of a string Given a string s and an integer k. The task is to perform a mirror transformation on the substring starting from the k-th position to the end of the string. In this transformation, each letter is replaced by its corresponding mirrored letter in the English alphabet ('a' -> 'z', 'b' -> 'y', 'c' 6 min read Concatenated string with uncommon characters in Python The goal is to combine two strings and identify the characters that appear in one string but not the other. These uncommon characters are then joined together in a specific order. In this article, we'll explore various methods to solve this problem using Python.Using set symmetric difference We can 3 min read Python - Check if String Contain Only Defined Characters using Regex In this article, we are going to see how to check whether the given string contains only a certain set of characters in Python. These defined characters will be represented using sets. Examples: Input: â657â let us say regular expression contains the following characters- (â78653â) Output: Valid Exp 2 min read Find all strings that match specific pattern in a dictionary Given a dictionary of words, find all strings that match the given pattern where every character in the pattern is uniquely mapped to a character in the dictionary. Examples: Input: dict = ["abb", "abc", "xyz", "xyy"]; pattern = "foo" Output: [xyy abb] xyy and abb have same character at index 1 and 15+ min read Check if String Contains Substring in Python This article will cover how to check if a Python string contains another string or a substring in Python. Given two strings, check whether a substring is in the given string. Input: Substring = "geeks" String="geeks for geeks"Output: yesInput: Substring = "geek" String="geeks for geeks"Output: yesEx 8 min read Python | Check order of character in string using OrderedDict( ) Given an input string and a pattern, check if characters in the input string follows the same order as determined by characters present in the pattern. Assume there wonât be any duplicate characters in the pattern. Examples: Input: string = "engineers rock"pattern = "er";Output: trueExplanation: All 3 min read Like