I have a python dictionary
graph = {'A': ['B', 'C','B'], 'E': ['C', 'D']}
I would like to remove the duplicate values from my dictionary & would like to have in this form
graph = {'A': ['B', 'C'], 'E': ['C', 'D']}
This is the sample dataset. I'm not sure for how many cases it's occurring. Can you suggest me how to do that?
All you need is to convert list into set and then back into list.
graph = {'A': ['B', 'C','B'], 'E': ['C', 'D']}
for idx, k in enumerate(graph):
graph[k] = list(set(graph[k]))
print(graph)