def try_add_value_case_insensitive(d, key_name, new_value):
    """
    Look in a dictionary for a key with the given key_name, without concern
    for case. If the key is found, return the associated value. Otherwise, set
    the value to that provided.
    """
    for name, value in d.items():
        if name.lower() == key_name.lower():
            return value
    d[key_name] = new_value
    return new_value