📜  如何在嵌套字典python代码示例中获取键值

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

代码示例2
def recursive_items(dictionary):
    for key, value in dictionary.items():
        if type(value) is dict:
            yield from recursive_items(value)
        else:
            yield (key, value)

a = {'a': {1: {1: 2, 3: 4}, 2: {5: 6}}}

for key, value in recursive_items(a):
    print(key, value)