我的输入是:
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'
蝴蝶不菲
天涯尽头无女友
守着一只汪
相关分类