def apply_substitution(subst_dict, cleaned_string):
    """ Apply a substitution dictionary to a string.

    """
    encoded_string = ''

    # Slightly confusing, the get function will get the value of the
    # key named letter or will return letter.
    for letter in cleaned_string:
        letter = letter.lower()
        if letter in subst_dict:
            encoded_string += subst_dict.get(letter, letter)
        else:
            encoded_string += letter
    
    return encoded_string