[Python-ideas] Add "default" kw argument to operator.itemgetter and operator.attrgetter

Rob Cliffe rob.cliffe at btinternet.com
Sat May 5 18:25:04 EDT 2018


>> At some point, we're really better off just using a lambda.
> Maybe I'm slow today, but I'm having trouble seeing how to write this as
> a lambda.
 >>> values = {'x': 43, 'y': 55}
 >>> x, y, z = (lambda *args : tuple(values.get(arg,0) for arg in 
args))('x','y','z')
 >>> print(x, y, z)
(43, 55, 0)
 >>>

Rob Cliffe


More information about the Python-ideas mailing list