I am trying to sort out a dictionary so that the original can of the original dictionary can now be the key, and the original key will be grouped together by value as a list. Example shown below:
#original dict
dictionary = {"Hello":5,"Jacket":5,"Brackets":6,"Coat":3,"Comma":6,"quotation":3}
desired output:
Revised = {5:["Hello","Jacket"],6:["Brackets","Comma"],3:["Coat","quotation"]}
I tried the following:
def find():
hello = dict()
for item in dictionary:
if dictionary[item] not in hello.values():
hello[item] = item
else:
hello[item].append(item)
return hello
hello = find()
However, I get a dictionary that is like this:
Wrong = {"Brackets":"Brackets","Coat":"Coat","Comma":"Comma","Hello":"Hello","Jacket":"Jacket","quotation":"quotation"}
What is the problem with by code, and how can I fix it? Thanks!!