map reduce 用法 str处理lower() capitalize()
--
s=''
l={'':0,'':1,'':2,'':3,'':4,'':5,'':6,'':7,'':8,'':9}[s[0]]
print(l)
取出dic里面key的元素
def normalize(name):
tempn=name.lower().capitalize()
return tempn
L1 = ['adam', 'LISA', 'barT']
L2 = list(map(normalize, L1))
print(L2)
只大写第一个字母,其余小写 其中用到 字符串 lower() capitalize() 函数
##sum
num1=[20,30,50]
print(sum(num1[1:]))
##multiply
def prod(L):
return reduce(lambda x,y:x*y ,L)
L3=[1,2,3,4,6]
print(prod(L3[:2]))
print(1*2)
List 求和和求积函数 其中用到 reduce lambda表达式
def str2float(s):
tempstr=s.split('.')
ustr=tempstr[0]+tempstr[1]
def str2num(r):
return {'': 0, '': 1, '': 2, '': 3, '': 4, '': 5, '': 6, '': 7, '': 8, '': 9}[r]
ws=len(tempstr[1])
return reduce(lambda x, y: x * 10 + y, map(str2num, ustr))/(10**ws)
--str转换float函数。 思路去掉小数点,转换成整数,然后除以小数点的位数。
map reduce 用法 str处理lower() capitalize()的更多相关文章
- lodash用法系列(4),使用Map/Reduce转换
Lodash用来操作对象和集合,比Underscore拥有更多的功能和更好的性能. 官网:https://lodash.com/引用:<script src="//cdnjs.clou ...
- Python语言——map/reduce的用法
Python内建了map()和reduce()函数. 如果你读过Google的那篇大名鼎鼎的论文“MapReduce: Simplified Data Processing on Large Clus ...
- python中filter,reduce,map的用法
filter的用法: 操作表list的内嵌函数'filter' 需要一个函数与一个list它用这个函数来决定哪个项应该被放入过滤结果队列中遍历list中的每一个值,输入到这个函数中如果这个函数返回Tr ...
- python基础——map/reduce
python基础——map/reduce Python内建了map()和reduce()函数. 如果你读过Google的那篇大名鼎鼎的论文“MapReduce: Simplified Data Pro ...
- Python进阶:函数式编程(高阶函数,map,reduce,filter,sorted,返回函数,匿名函数,偏函数)...啊啊啊
函数式编程 函数是Python内建支持的一种封装,我们通过把大段代码拆成函数,通过一层一层的函数调用,就可以把复杂任务分解成简单的任务,这种分解可以称之为面向过程的程序设计.函数就是面向过程的程序设计 ...
- (转)Python进阶:函数式编程(高阶函数,map,reduce,filter,sorted,返回函数,匿名函数,偏函数)
原文:https://www.cnblogs.com/chenwolong/p/reduce.html 函数式编程 函数是Python内建支持的一种封装,我们通过把大段代码拆成函数,通过一层一层的函数 ...
- 高阶函数:map()/reduce()
Python内建了map()和reduce()函数. 如果你读过Google的那篇大名鼎鼎的论文“MapReduce: Simplified Data Processing on Large Clus ...
- 函数式编程 高阶函数 map&reduce filter sorted
函数式编程 纯函数:没有变量的函数 对于纯函数而言:只要输入确定,那么输出就是确定的.纯函数是没有副作用的. 函数式编程:允许把函数本身作为参数传入另一个函数,还允许返回一个函数 高阶函数:一个函数的 ...
- python笔记十四(高阶函数——map/reduce、filter、sorted)
一.map/reduce 1.map() map(f,iterable),将一个iterable对象一次作用于函数f,并返回一个迭代器. >>> def f(x): #定义一个函数 ...
随机推荐
- hibernate ID
一:主键生成策略大体分类: 1:hibernate 负责对主键ID赋值 2:应用程序自己为主键ID赋值(不推荐使用) 3:底层数据库为主键ID赋值 二:具体用法 ...
- hibernateTemplate API
https://docs.spring.io/spring-framework/docs/2.5.x/api/org/springframework/orm/hibernate3/HibernateT ...
- java NIO 文章
http://tutorials.jenkov.com/java-nio/ 总结nio nio是非阻塞的,一个线程可以管多个Channel,每个channel可以处理bytebuffer 而no是阻塞 ...
- go语言指针判等
https://blog.csdn.net/qq_26981997/article/details/52608081
- 2018面向对象程序设计(Java)第1周学习指导及要求
2018面向对象程序设计(Java) 第1周学习指导及要求(2018.8.24-2018.9.2) 学习目标 了解课程上课方式及老师教学要求,掌握课程学习必要的软件工具: 简单了解Java特点及历 ...
- Velocity Obstacle
[Velocity Obstacle] Two circular objects A,B, at time t(0), with velocity V(A),V(B). A represent the ...
- npm run build
[npm run build] npm 会在项目的 package.json 文件中寻找 scripts 区域,其中包括npm test和npm start等命令. 其实npm test和npm st ...
- VS2013 warning C4018 "<” 有符号/无符号不匹配
1, VS2013 warning C4018 "<” 有符号/无符号不匹配" 警告 出错代码: void show(const vector<int>& ...
- 虚拟机安装的ubutun全屏
虚拟机下面安装了ubuntu系统,显示的屏幕只有那么一小块儿,不知道如何才能全屏,那么如何全屏呢?且看下面经验. 方法/步骤 打开虚拟机,并点击要更改成全屏的那个ubuntu系统的电源 我 ...
- e-olymp Problem11 Big accuracy
传送门:点我 Big accuracy The rational fraction m/n is given. Write it in the decimal notation with k digi ...