lambda arguments unpack error

后端 未结 6 1855
名媛妹妹
名媛妹妹 2020-11-30 09:40

In Python 2 this code is OK:

f = lambda (m, k): m + k

m = [1,2,3,4]
k = [5,6,7,8]

print(map(f, zip(m, k)))

but in Python 3 the following

6条回答
  •  一向
    一向 (楼主)
    2020-11-30 09:54

    The removal of tuple unpacking is discussed in PEP 3113. Basically, you can't do this in Python 3. Under the headline Transition plan, you see that the "suggested" way of doing this is as your final code block:

    lambda x_y: x_y[0] + x_y[1]
    

提交回复
热议问题