Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python-比较两个字典_Python_List_Dictionary_Comparison - Fatal编程技术网

Python-比较两个字典

Python-比较两个字典,python,list,dictionary,comparison,Python,List,Dictionary,Comparison,我有一个文本文件,其中包含图像中不同对象的文本描述。例如,这是描述包含image1和image2的图像的文件文本。。它们有不同长度的圆圈 Image1 a shape:circle size:huge fill:no b shape:circle size:very large fill:no inside:a c shape:circle

我有一个文本文件,其中包含图像中不同对象的文本描述。例如,这是描述包含image1和image2的图像的文件文本。。它们有不同长度的圆圈

Image1
    a
        shape:circle
        size:huge
        fill:no
    b
        shape:circle
        size:very large
        fill:no
        inside:a
    c
        shape:circle
        size:large
        fill:no
        inside:a,b
  Image2
    f
        shape:circle
        size:large
        fill:no
    g
        shape:circle
        size:medium
        fill:no
        inside:f
    h
        shape:circle
        size:small
        fill:no
        inside:f,g
什么是一种有效(且不丑陋)的方法来比较这两者并描述它们的相似性和差异。这些图像被读入字典,这就是我正在比较它们的原因。属性包含从文本文件读取的所有信息

    for attrib, value in Image1.objects.iteritems():
            for key2,value2 in Image2.objects.iteritems():
                for o1, o2 in zip(value.attributes.iteritems(),value2.attributes.iteritems()):
                    if o1 == o2:
                        print 'ok', o1 , o2
                    else:
                        print 'nok', o1, o2
以下是此循环的输出:

ok ('shape', 'octagon') ('shape', 'octagon')
ok ('size', 'very large') ('size', 'very large')
最后,我想得到一个描述(可能是一个列表或字典??)在image2中添加了什么,删除了什么,修改了什么