Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.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
Sorting 按键比较两个字典列表并返回重复_Sorting_Python 3.x_Dictionary - Fatal编程技术网

Sorting 按键比较两个字典列表并返回重复

Sorting 按键比较两个字典列表并返回重复,sorting,python-3.x,dictionary,Sorting,Python 3.x,Dictionary,我有两个键相同但值不同的字典: dic1 = {'popped': ['question', '30', 'balloon', '18', 'zit', '10', 'popcorn', '6', 'pimple', '6', 'cherry', '5'], 'planted': ['tree', '30', 'seed', '28', 'flower', '20', 'plant', '7', 'bomb', '4', 'garden', '2'], 'distilled ': ['water

我有两个键相同但值不同的字典:

dic1 = {'popped': ['question', '30', 'balloon', '18', 'zit', '10', 'popcorn', '6', 'pimple', '6', 'cherry', '5'],
'planted': ['tree', '30', 'seed', '28', 'flower', '20', 'plant', '7', 'bomb', '4', 'garden', '2'],
'distilled ': ['water', '45', 'vodka', '9', 'vinegar', '7', 'beer', '6', 'alcohol', '5', 'whiskey', '5'] }

我想比较两者,找出两者中重复的值,这样我的结果会是:

dic3 = {'popped ': ['balloon', 'question', 'popcorn'], 
'planted ': ['flower', 'tree', 'seed'], 
'distilled  ': ['water', 'vinegar','alcohol']}
我尝试了一些不同的事情,但我离成功还差得远。你对每个方向都有什么建议吗?我非常感谢你

dic3=dict()

    for key, val in dic1.items():
        val2=dic2[key]

        val3=set(val).intersection(set(val2))
        dic3[key]=val3
dic3=dict()

    for key, val in dic1.items():
        val2=dic2[key]

        val3=set(val).intersection(set(val2))
        dic3[key]=val3