📌  相关文章
📜  如何检查python代码示例中是否存在嵌套哈希元素

📅  最后修改于: 2022-03-11 14:46:45.036000             🧑  作者: Mango

代码示例1
def keys_exists(element, *keys):
    '''
    Check if *keys (nested) exists in `element` (dict).
    '''
    if not isinstance(element, dict):
        raise AttributeError('keys_exists() expects dict as first argument.')
    if len(keys) == 0:
        raise AttributeError('keys_exists() expects at least two arguments, one given.')

    _element = element
    for key in keys:
        try:
            _element = _element[key]
        except KeyError:
            return False
    return True