def hierarchical_match(d, k, default=None):
    """
    Match a key against a dict, simplifying element at a time


    :param df: DataFrame
    :type df: pandas.DataFrame
    :param level: Level of DataFrame index to extract IDs from
    :type level: int or str
    :return: hiearchically matched value or default
    """
    if d is None:
        return default

    if type(k) != list and type(k) != tuple:
        k = [k]

    for n, _ in enumerate(k):
        key = tuple(k[0:len(k)-n])
        if len(key) == 1:
            key = key[0]

        try:
            d[key]
        except:
            pass
        else:
            return d[key]
    return default
def hierarchical_match ( d , k , default = None ) : if d is None : return default if type ( k ) != list and type ( k ) != tuple : k = [ k ] for n , _ in enumerate ( k ) : key = tuple ( k [ 0 : len ( k ) - n ] ) if len ( key ) == 1 : key = key [ 0 ] try : d [ key ] except : pass else : return d [ key ] return default
Match a key against a dict, simplifying element at a time


    :param df: DataFrame
    :type df: pandas.DataFrame
    :param level: Level of DataFrame index to extract IDs from
    :type level: int or str
    :return: hiearchically matched value or default