I’ve been trying to remove a specific item from multiple values in a dictionary in python and am not completely sure how to do this. For example, in the dictionary:
d = {('hello', 'hi', 'how are you'): 2, ('hi', 'hello', 'how are you'): 1}
How would I remove ‘hi’ so that all that remains is:
d = {('hello', 'how are you'): 2, ('hello', 'how are you'): 1}
You apparently want to change the key. So you simply need to store the corresponding value with the new key and remove the old one. However, in your case creating a new dict is easier since you want to modify every single item.
d2now contains{('hello', 'how are you'): 1}As you can see it contains only one value unlike in your example because dicts cannot contain the same key twice.