【发布时间】:2019-09-06 10:59:59
【问题描述】:
我的输入是:
files = {
'Input.txt': 'Randy',
'Code.py': 'Stan',
'Output.txt': 'Randy'
}
我希望输出为:
{'Randy':['Input.txt','Output.txt'], 'Stan':['Code.py']}
基本上是这个switch key and values in a dict of lists的另一个方向
这是我尝试过的:
dictresult= {}
for key,value in files.items():
dictresult[key]=value
dictresult[value].append(key)
但它不起作用。我得到KeyError: 'Randy'
【问题讨论】:
标签: python dictionary