How do you check the presence of many keys in a Python dictinary?
- by Thierry Lam
I have the following dictionary:
sites = {
'stackoverflow': 1,
'superuser': 2,
'meta': 3,
'serverfault': 4,
'mathoverflow': 5
}
To check if there are more than one key available in the above dictionary, I will do something like:
'stackoverflow' in sites and 'serverfault' in sites
The above is maintainable with only 2 key lookups. Is there a better way to handle checking a large number of keys in a very big dictionary?