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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -