def find_value_in_dict()

in android_sdk/AndroidExtraXMLParser.py [0:0]


def find_value_in_dict(thedict, key):
    """Iterate through a dict to find all matching keys, even if inside another
    dict."""
    resultlist = list()
    if key not in thedict:
        # it might be buried inside a dict as a value
        for value in thedict.values():
            if type(value) == list:
                templist = list()
                for newvalue in value:
                    result = find_value_in_dict(newvalue, key)
                    if result:
                        templist.append(result)
                if len(templist) == 1:
                    resultlist = templist[0]
                else:
                    resultlist.extend(templist)
    else:
        "Adding to dict 2 %s" % key
        resultlist.append(thedict[key])
    return resultlist