ASCII Table Representation of Text

  • Share this:

Code introduction


This function converts an input string into an ASCII table, represented by dots for non-ASCII characters.


Technology Stack : String manipulation, list comprehension, character encoding

Code Type : Function

Code Difficulty : Intermediate


                
                    
def ascii_table(text):
    """
    Convert a string to an ASCII table.
    """
    ascii_chars = [chr(i) for i in range(32, 127)]
    table = ""
    for char in text:
        if char in ascii_chars:
            table += f"{char} "
        else:
            table += ". "
    return table.strip()