Python map()
2018-02-13 14:00
183 查看
个人观点:map函数就是用在单个元素在的函数处理;
reduce函数用的是两个元素的处理,两者作用是类似的。
描述
map() 会根据提供的函数对指定序列做映射。第一个参数 function 以参数序列中的每一个元素调用 function 函数,返回包含每次 function 函数返回值的新列表。语法
map() 函数语法:map(function, iterable, ...)参数
function -- 函数,有两个参数iterable -- 一个或多个序列
返回值
Python 2.x 返回列表。Python 3.x 返回迭代器。实例
以下实例展示了 map() 的使用方法:>>>def square(x) : # 计算平方数... return x4000
** 2... >>> map(square, [1,2,3,4,5]) # 计算列表各个元素的平方[1, 4, 9, 16, 25]>>> map(lambda x: x ** 2, [1, 2, 3, 4, 5]) # 使用 lambda 匿名函数[1, 4, 9, 16, 25] # 提供了两个列表,对相同位置的列表数据进行相加>>> map(lambda x, y: x + y, [1, 3, 5, 7, 9], [2, 4, 6, 8, 10])[3, 7, 11, 15, 19]
相关文章推荐
- 【Python】map/reduce函数相关练习
- python:内建函数、range()、map()、filter()、reduce()、sorted()、集合的使用、functools中的函数使用、MD5加密
- Python特殊语法:filter、map、reduce、lambda [转]
- python map 常见用法
- Python中map和列表推导效率比较实例分析
- Python函数之map、reduce、filter
- python3下使用map()函数返回<map object at 0x00000000038327F0>导致不能直接使用的解决办法
- Python之map(),reduce(),filter()函数
- python中的map、filter、reduce函数
- Python特殊语法:filter、map、reduce、lambda、yield
- Python map/reduce/lambda
- python的map,reduce和zip
- python学习9--lambda,map,filter,递归
- Python的filter, map, reduce, lambda
- Python实用技巧---列表推导式(轻量级循环)与map
- Python的map、filter、reduce函数
- python学习笔记--zip()和map()
- python中map()函数
- Python资料之map()函数
- python filter,map,lambda