I need to check if a particular key is present in some dictionary. I can use has_key ?? Is there any other method to compare the items of the list to the key of dictionary.
I have a list like…[(3,4),(4,5)..]
I need to check if the (3,4) is there in the dictionary.
The “right” way is using the
inoperator like what the other answers have mentioned. This works for anything iterable and you get some speed gains when you can look things up by hashing (like for dictionaries and sets). There’s also an older way which works only for dictionaries which is thehas_keymethod. I don’t usually see it around these days and it’s slower as well (though not by much).