Is there a nice approach to test if a dictionary contains multiple keys?
A short version of:
d = {}
if 'a' in d and 'b' in d and 'c' in d:
pass #do something
Thanks.
Edit: I can only use python2.4 -.-
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use
set.issubset(...), like so:Python 3 has introduced a set literal syntax which has been backported to Python 2.7, so these days the above can be written: