How do I check that multiple keys are in a dict in a single pass?

Well, you could do this:

>>> if all (k in foo for k in ("foo","bar")):
...     print "They're there!"
...
They're there!

Leave a Comment