A to Z Sorting Function with ASCII Modulo Rule

  • Share this:

Code introduction


This function sorts the characters in the input string from 'a' to 'z' and returns the sorted string. The sorting rule is based on the ASCII value of the characters, achieved by subtracting 96 and taking modulo 26.


Technology Stack : String handling

Code Type : Function

Code Difficulty : Beginner


                
                    
def a_to_z_sorter(input_string):
    return ''.join(sorted(input_string, key=lambda x: (ord(x) - 96) % 26))