ASCII Table Conversion Function

  • Share this:

Code introduction


This function takes a string as input and returns a dictionary. The keys of the dictionary are the characters in the string, and the values are lists containing the ASCII codes of those characters.


Technology Stack : string, dictionary

Code Type : Function

Code Difficulty : Intermediate


                
                    
def ascii_table(text):
    """
    将文本转换为ASCII字符表的形式。
    """
    table = {}
    for char in text:
        if char in table:
            table[char].append(ord(char))
        else:
            table[char] = [ord(char)]
    return table