For a Python Dictionary with a tuple key, how can only the part of the dictionary with one of the tuple elements set to a single value be displayed. Then also looking to delete those elements.
For example, the dictionary
testTrak = {(0,1): '+', (0,2): '-', (1,1): '34.0', (1,2): 'test'}
and I want to list only the elements with the first number of the tuple = 1; that is, I want to list only (1,*) where the asterisk represents a wild card; hence, only
(1,1): '34.0' and (1,2): 'test' would be listed.
It seems maybe some kind of slicing should work but don’t see it.
Sorry, I misread your question. Here’s the solution you need for pretty much any Python version:
In Python 2.7+ you can write the less verbose version:
Excluding the items is just a matter negating the if clause, if this is what you asked in the comments: