Python map() 函数
2023-09-11 14:17:15 时间
功能:根据提供的函数对指定序列做映射
第一个参数 function 以参数序列中的每一个元素调用 function 函数,返回包含每次 function 函数返回值的新列表。
语法:map(function, iterable, ...)
参数:function:函数
iterable:一个或多个可迭代序列
实例:
def square(x):
return x ** 2
list(map(square(x), [1,2,3,4,5]))
输出:[1, 4, 9, 16, 25]
也可使用 lambda 匿名函数:
list(map(lambda x: x ** 2, [1,2,3,4,5]))
输出:[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、filter函数用法
- 【Python】python 多线程两种实现方式
- python map() 函数
- python:ERROR: No matching distribution found for Pillow==9.1.0的处理(Python 3.6.8)
- python中的map()函数
- Python 字符串_python 字符串截取_python 字符串替换_python 字符串连接
- python:ERROR: No matching distribution found for Pillow==9.1.0的处理(Python 3.6.8)
- Python语言学习:解决python版本升级问题集合(python2系列→Python3系列)导致错误的总结集合
- Python之API:基于python语言调用华为云API(华为网站)实现特定功能
- 人工智能——K-Means聚类算法(Python)
- Python 最频繁使用的4个函数:lambda、 map、filter 和 reduce
- Python学习28:map/reduce
- python -filter、reduce、map、lambda函数
- Python爬虫:PyExecJS在python中运行javascript代码
- python 实现二叉树的最大深度
- Map生成器 map适配器如今能够使用各种不同的Generator,iterator和常量值的组合来填充Map初始化对象
- 10行Python代码自动清理电脑内重复文件,解放双手!
- 〖Python自动化办公篇㉑〗- python实现邮件自动化 - 定时发送邮件
- Python常用内置函数(python 3.x)