I was wondering if there is a pythonic way to delete an item completely from a dictionary. To illustrate that, consider the dict given below:
mydict = {'A': ['B', 'O'],
'B': ['A'],
'C': ['D', 'E', 'F', 'O'],
'D': ['E', 'C', 'F'],
'E': ['C', 'D', 'F', 'O'],
'F': ['C', 'D', 'E'],
'G': ['H', 'O'],
'H': ['G', 'O'],
'O': ['A', 'C', 'E', 'G', 'H']}
And let's say, I want to remove 'E' from the dictionary. Then I expect to get such a dictionary:
mydict = {'A': ['B', 'O'],
'B': ['A'],
'C': ['D', 'F', 'O'],
'D': ['C', 'F'],
'F': ['C', 'D', ],
'G': ['H', 'O'],
'H': ['G', 'O'],
'O': ['A', 'C', 'G', 'H']}
Of course, I can get it by looping over its keys and values. But, I am wondering if there is a better way to do that.