python的map如何处理几个参数

2024-05-23 17:56:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我有这个密码:

def funky_fun(lst):
    tmp = list(map(lambda x,y: x+y, lst[1:], lst[:-1]))
    print('check:', tmp, lst[1:] + lst[:-1])
    return [lst[0]] + tmp + [lst[-1]]

print(funky_fun(funky_fun([1])))

这里funky_fun([1])返回[1, 1],而第二个调用(funky_fun([1, 1])返回[1, 2, 1]。你知道吗

你明白为什么吗?因为lsr[1:][1],而lst[:-1]也是[1],所以我认为它会打印[1, 1, 1, 1],但是tmp[2]。 它可能和我不懂的map函数有关。你知道吗


Tags: lambda函数密码mapreturndefcheckfunky