Given a dictionary keyed by 2-element tuples, I want to return all the key-value pairs whose keys contain a given element.
For example, the dictionary can be:
tupled_dict = {('a',1):1, ('a',2):0, ('b',1):1, ('c',4):0}
and the given element is 'a', then the key-value pairs that should be returned would be:
('a',1):1, ('a',2):0
What is the fastest code to do this?
EDIT:
In addition, as a related sub-question, I am interested in the fastest way to delete all such key-value pairs given an element of the keys. Obviously, once I have the results of the above, I can use a loop to delete each dictionary item one by one, but I wonder if there is a short-cut way to do it.
To get those ones:
Similarly, to delete the other ones: