python:map函数练习
2017-03-20 12:47
337 查看
题目1:利用
代码:def chm(x):
return x[0].upper()+x[1:].lower()
map(chm,['adam','LISA':'barT'])
题目2:Python提供的
代码:def prod(x,y):
return x*y
reduce(prod,[1,2,3,4,5,6])
map()函数,把用户输入的不规范的英文名字,变为首字母大写,其他小写的规范名字。输入:
['adam', 'LISA', 'barT'],输出:
['Adam', 'Lisa', 'Bart']
代码:def chm(x):
return x[0].upper()+x[1:].lower()
map(chm,['adam','LISA':'barT'])
题目2:Python提供的
sum()函数可以接受一个list并求和,请编写一个
prod()函数,可以接受一个list并利用
reduce()求积。
代码:def prod(x,y):
return x*y
reduce(prod,[1,2,3,4,5,6])
相关文章推荐
- 【Python】map/reduce函数相关练习
- python的几个内建函数:apply(),filter(),map(),reduce(
- python map内建函数
- Python中map()内建函数浅析
- Python中map()函数浅析
- python 内建函数map&reduce
- Python内建函数之——filter,map,reduce
- Python 内建函数,filter,map, reduce
- [Python] 函数lambda(), filter(), map(), reduce()
- [Python] 函数lambda(), filter(), map(), reduce()
- Python中map()函数浅析
- python的几个内建函数:apply(),filter(),map(),reduce()
- python中map()函数的使用
- python中map()函数的使用 分类: python 2012-12-20 16:18 121人阅读 评论(0) 收藏
- [Python] 函数lambda(), filter(), map(), reduce()
- python的几个内建函数:apply,filter,map,reduce
- python map函数用法
- Python中map()函数浅析
- Python中map()函数浅析
- Python内建函数之——filter,map,reduce