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