當前位置:成語大全網 - 新華字典 - python求壹個字典中相同鍵值的分組列表

python求壹個字典中相同鍵值的分組列表

a = {'a':'asdg','b':'asd','c':'asd','1':'asdg',1:'asdg'}

new_dict = {}

for k, v in a.items():

new_dict.setdefault(v, []).append(k)

for k,v in new_dict.items():

res = {}

for lv in v:

res[lv] = k

print(res)