--

 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()的更多相关文章

  1. lodash用法系列(4),使用Map/Reduce转换

    Lodash用来操作对象和集合,比Underscore拥有更多的功能和更好的性能. 官网:https://lodash.com/引用:<script src="//cdnjs.clou ...

  2. Python语言——map/reduce的用法

    Python内建了map()和reduce()函数. 如果你读过Google的那篇大名鼎鼎的论文“MapReduce: Simplified Data Processing on Large Clus ...

  3. python中filter,reduce,map的用法

    filter的用法: 操作表list的内嵌函数'filter' 需要一个函数与一个list它用这个函数来决定哪个项应该被放入过滤结果队列中遍历list中的每一个值,输入到这个函数中如果这个函数返回Tr ...

  4. python基础——map/reduce

    python基础——map/reduce Python内建了map()和reduce()函数. 如果你读过Google的那篇大名鼎鼎的论文“MapReduce: Simplified Data Pro ...

  5. Python进阶:函数式编程(高阶函数,map,reduce,filter,sorted,返回函数,匿名函数,偏函数)...啊啊啊

    函数式编程 函数是Python内建支持的一种封装,我们通过把大段代码拆成函数,通过一层一层的函数调用,就可以把复杂任务分解成简单的任务,这种分解可以称之为面向过程的程序设计.函数就是面向过程的程序设计 ...

  6. (转)Python进阶:函数式编程(高阶函数,map,reduce,filter,sorted,返回函数,匿名函数,偏函数)

    原文:https://www.cnblogs.com/chenwolong/p/reduce.html 函数式编程 函数是Python内建支持的一种封装,我们通过把大段代码拆成函数,通过一层一层的函数 ...

  7. 高阶函数:map()/reduce()

    Python内建了map()和reduce()函数. 如果你读过Google的那篇大名鼎鼎的论文“MapReduce: Simplified Data Processing on Large Clus ...

  8. 函数式编程 高阶函数 map&reduce filter sorted

    函数式编程 纯函数:没有变量的函数 对于纯函数而言:只要输入确定,那么输出就是确定的.纯函数是没有副作用的. 函数式编程:允许把函数本身作为参数传入另一个函数,还允许返回一个函数 高阶函数:一个函数的 ...

  9. python笔记十四(高阶函数——map/reduce、filter、sorted)

    一.map/reduce 1.map() map(f,iterable),将一个iterable对象一次作用于函数f,并返回一个迭代器. >>> def f(x): #定义一个函数 ...

随机推荐

  1. Django 基础教程中的Django表单

    在 urls.py 中对应写上这个函数,教程中给的Django 1.7x以下的,我的时2.0.7,应该为 from django.contrib import admin from django.ur ...

  2. chrome 扩展 调试

    开发chrome扩展,有时候需要输出console.log 通常调试的popup.html.content_script.backgroup.html等 但是有一些是没有这些的 1.推荐一个扩展: h ...

  3. cekephp 事务处理

    $sw = $this->Orders->getDataSource(); $sw->begin(); $this->Orders->commit() $this-> ...

  4. spring学习第一课:spring的jar包下载

    感谢作者: http://yanln.iteye.com/blog/2191312 ---------------------------------------------------------- ...

  5. js常用返回网页顶部几种方法

    一.使用锚标记 此方法最简单,只需在body下放个隐藏的锚点标记,内容如下:  代码如下 复制代码 <a name="top" id="top">& ...

  6. LibreOJ 6277. 数列分块入门 2

    题目链接:https://loj.ac/problem/6278 参考博客:https://blog.csdn.net/qq_36038511/article/details/79725027 这题我 ...

  7. PAT1131(dfs)

    In the big cities, the subway systems always look so complex to the visitors. To give you some sense ...

  8. UVA1588-Kickdown

    2018-10-30-18:27:03 原题链接 题目描述: 给出两个长度分别为n1,n2且每列高度只为1或2的长条,需要将它们放入一个高度为3的容器,求出能够容纳他们的最短容器长度. 本题思路: 模 ...

  9. python中if not x: 和 if x is not None: 和 if not x is None的使用和区别

    代码中经常会有变量是否为None的判断,有三种主要的写法: 第一种是`if x is None`: 第二种是 `if not x:`: 第三种是`if not x is None`(这句这样理解更清晰 ...

  10. 设置Tomcat的JAVA_OPTS参数

    修改$TOMCAT_HOME/bin/catalina.bat 添加set JAVA_OPTS= ... rem ----- Execute The Requested Command ------- ...