import string


def str_to_key(str1:str) -> str:
    """Convert a string to a string usable as a key"""
    # Remove any trailing white space
    str1 = str1.strip()

    # Add underscore if 1st character is a number
    if str1[0].isdigit():
        str1 = '_' + str1
    
    # Replace any non-letters with '_'
    _strings = [t if t in string.ascii_letters + string.digits else '_' for t in str1]
    ans = "".join(_strings)
    return ans