【发布时间】:2019-11-18 19:38:00
【问题描述】:
我有两本这样的字典
dict_1 = {'adbc.txt':'Text','union.pdf':'pdf', 'file1.py':'Python'}
dict_2 = {'adbc.txt':['a.txt','b.txt','c.txt'], 'file1.py':['test.py', 'modified.py']}
我需要在 Python 中获得以下结果。有人可以帮忙吗
result = {'a.txt':'Text','b.txt':'Text','c.txt':'Text','test.py':'Python', 'modified.py':'Python', 'union.pdf':'pdf'}
'adbc.txt' 和 'file1.py' 键是两个字典中的通用键,我必须得到上述结果。
【问题讨论】:
-
您能否发布您编写的代码来尝试执行此操作,以及它是如何缩短的?也许提供你的结果背后的原因?
标签: python python-2.7 dictionary