For example, I have the following dictionary
{'key1':value1,'key2':value2,'key3':value1,.......}}
I want to change it to the following form:
{value1:[key1,key2],value2:[key3],....}
I have written the following to accomplish this task. However, I am not sure if this is the best way to go about it. Is there a better way to perform this task ?
node_cluster = {}
for node,cluster in zip(partition.keys(),partition.values()):
if cluster not in node_cluster.keys():
node_cluster[cluster] = []
node_cluster[cluster].append(node)