文章内容
2021/3/26 14:24:03,作 者: 黄兵
Python Map 函数
Map() 是一种内置的 Python 函数,它可以将函数应用于各种数据结构中的元素,如列表或字典。对于这种运算来说,这是一种非常干净而且可读的执行方式。
def square_it_func(a): return a * a x = map(square_it_func, [1, 4, 7]) print(x) # prints [1, 16, 47] def multiplier_func(a, b): return a * b x = map(multiplier_func, [1, 4, 7], [2, 5, 8]) print(x) # prints [2, 20, 56] 看看上面的示例!
评论列表