Is there a short-circuiting dictionary "get" method?
Jeff Epler
jepler at unpythonic.net
Wed Mar 9 18:20:02 EST 2005
untested
def my_getter(m, i, f):
try:
return m[i]
except (KeyError, IndexError):
return f()
my_getter(d, 'x', bigscaryfunction)
my_getter(d, 'y', lambda: scaryinlineexpresion)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20050309/7a457fe8/attachment.sig>
More information about the Python-list
mailing list