Alphabet Position Conversion

  • Share this:

Code introduction


Converts each letter in the input string to its corresponding position in the alphabet, then converts it back to the corresponding letter, and finally concatenates these letters in order to form a new string.


Technology Stack : Built-in functions (ord(), chr(), sum(), zip(), join(), list comprehension)

Code Type : String conversion

Code Difficulty : Intermediate


                
                    
def a_to_z_sequence(string):
    def ord_transform(char):
        return ord(char) - ord('a') + 1

    def z_transform(num):
        return chr(num + ord('a') - 1)

    return ''.join(z_transform(ord_transform(char)) for char in string.lower() if char.isalpha())