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

Bill Mill bill.mill at gmail.com
Wed Mar 9 13:18:35 EST 2005


On 9 Mar 2005 10:05:21 -0800, bearophileHUGS at lycos.com
<bearophileHUGS at lycos.com> wrote:
> Maybe this can help:
> 
> value = d.get('x', lambda: bigscaryfunction())

>>> def test(): print 'gbye'
...
>>> d = {}
>>> z = d.get('x', lambda: test())
>>> z
<function <lambda> at 0x008D6870>

So this seems to be merely an obfuscation of:

>>> z = d.get('x', test)
>>> z
<function test at 0x008D66B0>

I just wanted to ask, am I missing something?

Peace
Bill Mill
bill.mill at gmail.com



More information about the Python-list mailing list