map函数形参为一个函数和一个迭代对象

给定一个列表,实现加1

L = [1, 2, 3, 4, 5]

res = map(lambda x:x+1, L)

print(list(res))

# 不使用map函数,实现的效果是一模一样的
def add_test(x):
  return x+1

def map_test(func, array):
  temp = []
  for i in array:
    res = func(i)
    temp.add(res)
  return temp

res = map_test(add_test, L)
print(res)

 

相关文章:

  • 2022-12-23
  • 2021-10-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-03-01
  • 2021-10-11
  • 2022-12-23
  • 2021-11-06
  • 2021-09-23
相关资源
相似解决方案