Is there a short-circuiting dictionary "get" method?

Steve Holden steve at
Fri Mar 11 10:12:19 CET 2005

Terry Reedy wrote:
> "Skip Montanaro" <skip at> wrote in message 
> news:16943.18475.568383.983546 at
>>   value = d.get('x') or bsf()
>>Of course, this bsf() will get called if d['x'] evaluates to false, not 
> value = (d.get('x') is not None) or bsf() #??
Unfortunately this will set value to True for all non-None values of 
d['x']. Suppose d['x'] == 3:

  >>> 3 is not None


More information about the Python-list mailing list