我的输入是:
files = {
'Input.txt': 'Randy',
'Code.py': 'Stan',
'Output.txt': 'Randy'
}
我希望得到以下输出结果:
{'Randy':['Input.txt','Output.txt'], 'Stan':['Code.py']}
基本上这是一个 将字典中的键和值互换 的问题。
这是我尝试过的方法:
dictresult= {}
for key,value in files.items():
dictresult[key]=value
dictresult[value].append(key)
但它不起作用。我收到了KeyError:'Randy'
的错误。