如何比较脚本 test.py(Python)中分别存储在 2 个不同函数中的 2 个字典



In test.py,

def module1():
    ....
    ....
    ....
    print dic1
module1()
def module2():
    ....
    ....
    ....
    print dic2
module2()

我想在test.py中拥有一个名为 module3() 的函数,它将以最简单的方式比较 2 个字典,并在它们是否匹配'not matched'不匹配时显示结果'matched'。有什么帮助吗?

为什么不直接返回字典?

def module1():
    ...
    ...
    ...
    return dic1
def module2():
    ...
    ...
    ...
    return dic2:
def module3():
    d1 = module1()
    d2 = module2()
    if d1 == d2:
        print 'matched'
    else:
        print 'not matched'

最新更新