def word_lookup(w: str, table: dict, default=None):
    """
    Translate a word into a value by looking up from a dict.
    First priority is case-sensitive, then the next priority is case-insensitive.
    In case the word does not exist in the dict, a KeyError exception is raised or a default value is returned.

    Args:
        w: word to translate
        table: a dict to translate the word by looking up
        default: If not None, this is the value to return in case the word does not exist in the table.

    Returns:
        Translated value for the word by looking up the word into table.
    """
    if w in table:                  # Match word in case-sentitive mode is the first priority
        return table[w]
    elif w.lower() in table:        # Then, case-insensitive
        return table[w.lower()]
    else:
        if default is not None:
            return default
        else:
            raise KeyError('Key `{}` not found'.format(w))