Alphabetic Character Position Converter

  • Share this:

Code introduction


This function converts all alphabetic characters in the input string to their corresponding positions in the English alphabet, while leaving non-alphabetic characters unchanged.


Technology Stack : String processing

Code Type : String conversion function

Code Difficulty : Intermediate


                
                    
def a_to_z_converter(string):
    alphabet = 'abcdefghijklmnopqrstuvwxyz'
    converted = ''
    for char in string.lower():
        if char.isalpha():
            converted += alphabet[ord(char) - ord('a')]
        else:
            converted += char
    return converted