Python:How to determine whether the dictionary contains multiple keys? -
d={'a':1, 'b':2, ...} if 'a' in d , 'b' in d , ...: pass
is there simple way determine multiple keys @ once? like:
if ['a', 'b'] in d:
you can do
if all(key in d key in ['a', 'b', 'c', ...]):
this may longer writing them out separately if you're testing couple, list of keys tested grows longer, way quicker, since have add key list , not write additional in d and
.
Comments
Post a Comment