Why is the default in dict.get(key[, default]) evaluated even if the key is in the dictionary?
>>> key = \'foo\' >>> a={} >>> b={k
use this instead
x = b.get(key) or a.get(key)
or and and are short circuit operators, so if b has the key it won't look at a. But problems will arise if you have falsy values in b. If that is the case you can do:
or
and
b
a
falsy
x = b[key] if key in b else a.get(key)