Say I have a list
list: [keith, roger, david], [5, nobody, 31], [attack, thomas, 4]
and a dictionary
dictionary: '55': <Trachea>, 'Roger': <Bert>
I want to delete the items in the dictionary that don’t match up with the SECOND part of the list of lists. In this example, I’d want to get rid of ’55’: but not ‘Roger’: . Thanks!
There are quicker ways to do it, but making a set
secondElementswill accelerate the queries and make itO(1)time. I edited your list because there were case-sensitivity issues, but you could also use(k.lower() in secondElements).