Say I have a function that returns a tuple of outputs:
def f():
return 'zero', 1
But I have to supply in-line a new anonymous function that returns only e.g. the zeroth element of that returned tuple. This is an easy one-liner with a lambda
:
lambda : f()[0] # returns 'zero'
Is there a way to do the same thing using functools
or similar?
Given that lambda
was allegedly 'planned to [be removed] from Python 3, as one of "Python's glitches"', I'm assuming there's a way to do this without lambda
, but I haven't been able to figure it out.
I know that functools.partial
can pretty much be a substitute for lambda
when managing a function's input arguments. But managing a function's outputs? Haven't figured it out.