我想做类似的事情:
foo = { 'foo': 1, 'zip': 2, 'zam': 3, 'bar': 4 } if ("foo", "bar") in foo: #do stuff
如何检查foo和是否都bar在 dict 中foo?
foo
bar
好吧,你可以这样做:
>>> if all (k in foo for k in ("foo","bar")): ... print "They're there!" ... They're there!