python3 map函数
来源:互联网 发布:arm linux centos 编辑:程序博客网 时间:2024/05/20 01:33
map()函数
map()是 Python 内置的高阶函数,它接收一个函数 f 和一个 list,并通过把函数 f 依次作用在 list 的每个元素上,得到一个新的 list 并返回。
people = ['Dr. Christopher Brooks', 'Dr. Kevyn Collins-Thompson', 'Dr. VG Vinod Vydiswaran', 'Dr. Daniel Romero']def split_title_and_name(person): title = person.split()[0] lastname = person.split()[-1] return '{} {}'.format(title, lastname)print(list(map(split_title_and_name, people)))
输出:
[‘Dr. Brooks’, ‘Dr. Collins-Thompson’, ‘Dr. Vydiswaran’, ‘Dr. Romero’]
对于list [1, 2, 3, 4, 5, 6, 7, 8, 9]
如果希望把list的每个元素都作平方,就可以用map()函数:
因此,我们只需要传入函数f(x)=x*x,就可以利用map()函数完成这个计算:
def f(x): return x*xprint map(f, [1, 2, 3, 4, 5, 6, 7, 8, 9])
阅读全文
0 0
- python3 map函数
- python3 map函数
- python3中的map函数详解
- python3中map函数的改动
- python3 中的 map,reduce,filter函数
- Python3中map函数的问题
- python3中的map,filter,reduce函数解析
- python3-map,filter,reduce,lambda函数
- python3 中的 map,reduce,filter函数
- python2和python3 map函数的区别
- 转载-Python3中map函数的问题
- python3的map函数显示问题
- Python3.4中filter函数,map函数和reduce函数
- Python3.4中filter函数,map函数和reduce函数
- Python3.4中filter函数,map函数和reduce函数
- Python3 基础:高阶函数和map/reduce
- python3中内建函数map()与reduce()的使用方法
- Python学习笔记: Python3中map、filter、reduce函数
- thrift/swift:对swift2thrift-generator-cli IDL生成工具的改进
- 初阶并发编程之——运用wait()与notify()实现线程之间的协作
- 冬至日感想
- Python爬取百度图片
- LeetCode 273. Integer to English Words
- python3 map函数
- 2_发放奖金总数
- 3_该数是多少
- 请大神指教,自己设计的给任意整数排序的程序
- 670. Maximum Swap
- iOS进阶--App功耗优化看这篇就够了
- keras 大数据的训练,迭代载入内存
- 12.10作业
- 月薪30K+:程序员必备成长宝典