There is my problem:
Suppose we have 3 functions : f, g, h and the following code
y = f(x)
a = g(y)
b = h(y)
I want to do this on a single line, like :
a,b = g(f(x)),h(f(x))
but this is not efficient if f is very slow ( and doesn't cache it's result)
I have one solution with a generator:
a,b = ((g(y),h(y)) for y in (f(x),)).next()
but this not very readable
I would like to do some thing like that :
with f(x) as y: a,b = g(y),h(y)
Does anyone have an idea?
( this is cheat
y = f(x);a = g(y);b = h(y)
)
code
import time
def f(t):
time.sleep(1)
print 'f called'
return t
def g(t): return 1
def h(t): return 2
a,b = g(f(x)),h(f(x))
a,b = ((g(y),h(y)) for y in (f(x),)).next()