将函数转换为lambda函数

时间:2017-01-21 15:08:33

标签: python python-3.x

我必须将以下函数转换为lambda函数,而不更改语义。我该怎么做?

u = 1

def method1(x):
    def method2(n):
        def method3(m):
            return x + n + m
        def method4():
            global u
            u += 1
        method4()
        return method3
    def method5(y):
        return x + y
    return method2, method5

编辑: 以下是我的尝试:

method1 x: method2 n: method3 m: x+n+m, method 4 (): method 3, method5 y: x+y, method2 method3

EDIT2:

method1 = lambda x:
    method2 = lambda n:
        method3 = lambda m:
         x + n + m
        method4 = lambda :
         global u
         u = u + 1
        #dont know how to integrate "method4() return method3"
    method5 = lambda y:
      x + y
    method2, method5

0 个答案:

没有答案