Multiple 'in' operators in Python?

后端 未结 2 862
醉话见心
醉话见心 2021-01-11 22:48

Is there a shorthand way of checking for keys in a dictionary?

Something that I can use instead of using multiple in and and

相关标签:
2条回答
  • 2021-01-11 23:14
    set(['somekey', 'someotherkey', 'somekeyggg']).issubset(d)
    
    0 讨论(0)
  • 2021-01-11 23:20
    all( word in d for word in [ 'somekey', 'someotherkey', 'somekeyggg' ] )
    
    0 讨论(0)
提交回复
热议问题