Is there a shorthand way of checking for keys in a dictionary?
Something that I can use instead of using multiple in and and operators - instead of the following:
('somekey' in d) and ('someotherkey' in d) and ('somekeyggg' in d)
Is there a shorthand way of checking for keys in a dictionary?
Something that I can use instead of using multiple in and and operators - instead of the following:
('somekey' in d) and ('someotherkey' in d) and ('somekeyggg' in d)
all( word in d for word in [ 'somekey', 'someotherkey', 'somekeyggg' ] )
split() is better, but I see no reason to change the other answers to follow this approach.word that's not in d. A list comprehension will create the entire list of boolean values before calling the all function. This is a really cool feature of using all() and any() with generator expressions.