python-内置函数map()
来源:互联网 发布:软件空下载 编辑:程序博客网 时间:2024/05/21 05:24
- map()函数
map()是 Python 内置的高阶函数,它接收一个函数 f 和一个 list,并通过把函数 f 依次作用在 list 的每个元素上,得到一个新的 list 并返回。
下图可以说明:
对应下面的代码
def f(x): return x*xprint map(f, [1, 2, 3, 4, 5, 6, 7, 8, 9])
任务:假设用户输入的英文名字不规范,没有按照首字母大写,后续字母小写的规则,请利用map()函数,把一个list(包含若干不规范的英文名字)变成一个包含规范英文名字的list:
输入:[‘adam’, ‘LISA’, ‘barT’]
输出:[‘Adam’, ‘Lisa’, ‘Bart’]
代码:(upper()与lower()函数用法)
def format_name(s): return s[0].upper() + s[1:].lower()print map(format_name, ['adam', 'LISA', 'barT'])
0 0
- python-内置函数map()
- python-内置函数map()
- Python内置函数-map()函数
- python内置函数:lambda、map、filter
- python内置函数map/reduce/filter
- python内置函数map/reduce/filter
- python map ,reduce filter内置函数使用说明
- python 内置函数map/filter/reduce
- python 内置函数 map、 reduce 、filter
- python 内置函数filter, lambda, map, reduce
- python 内置函数map、reduce的使用
- Python 内置函数 lambda、filter、map、reduce
- python内置函数map/reduce/filter
- python:模拟内置函数map的实现
- Python【map、reduce、filter】内置函数使用说明
- python内置函数lambda、filter、map、reduce
- python几个内置函数之-filter,map,reduce
- python 中的 filter, lambda, map, reduce 内置函数
- python-内置函数map()
- 搞笑图片
- Oracle数据文件的坏块,可分为物理坏块和逻辑坏块(转)
- Tomcat知识点
- 第八章 8-3 在状态报告上使用计时器
- python-内置函数map()
- An internal error occurred during: "Launching on Tomcat 7.x"
- Spring核心之loC
- RecyclerView notifyItemRemoved 的坑
- STM8S_003_TIM定时中断
- Redis配置
- http协议
- 声声慢
- spring系列(一)——简介和IOC