内容来自雪峰的官方网站。

1、Python提供的sum()函数可以接受一个list并求和,请编写一个prod()函数,可以接受一个list并利用reduce()求积。

from functools import reduce
def prod(L):
def f(x, y):
return x * y;
return reduce(f , L)

2、利用mapreduce编写一个str2float函数,把字符串'123.456'转换成浮点数123.456。

不会用map reduce。。。

from functools import reduce
def str2float(s):
c = ;
pw = ;
for x in s:
if x != '.':
c = c * + int(x)
posi = s.find('.', )
for i in range(len(s) - posi - ):
pw *= 0.1
return c * pw

pyDay15的更多相关文章

  1. py-day1-5 python 分割 、 字母大小转换

    # partition() 分割为3段 从左往右遇见的第一个开始 test = 'bassaiwoll' v = test.partition('s') print(v) ('ba', 's', 's ...

随机推荐

  1. 教程Xcode 下编译发布与提交App到AppStore

    The proplem of Prepare for Upload for App store upload Application App store 增加新应用的步骤. 1. 访问iTunesCo ...

  2. 《C++ Primer Plus》12.7 队列模拟 学习笔记

    Heather银行打算在Food Heap超市开设一个自动柜员机(ATM).Food Heap超市的管理者担心排队使用ATM的人流会干扰超市的交通,希望限制排队等待的人数.Heather银行希望对顾客 ...

  3. iOS-利用插件实时刷新模拟器(提高效率)

    解决办法: 1.需要给Xcode安装一个Alcatraz插件 安装完成后:点击window 下面的 package manager 安装我们今天的主角 2. ‘Injection Plugin for ...

  4. linux制作RPM包

    制作rpm包 1.制作流程1.1 前期工作 1)创建打包用的目录rpmbuild/{BUILD,SPECS,RPMS, SOURCES,SRPMS} 建议使用普通用户,在用户家目录中创建 2)确定好制 ...

  5. 【PHP】数字补零的两种方法

    在php中有两个函数,能够实现数字补零, str_pad() sprintf() 函数1 : str_pad 顾名思义这个函数是针对字符串来说的这个可以对指定的字符串填补任何其它的字符串 例如:str ...

  6. 代码片段,lucene基本操作(基于lucene4.10.2)

    1.最基本的创建索引: @Test public void testIndex(){ try { Directory directory = FSDirectory.open(new File(LUC ...

  7. 【BZOJ3939】[Usaco2015 Feb]Cow Hopscotch 动态规划+线段树

    [BZOJ3939][Usaco2015 Feb]Cow Hopscotch Description Just like humans enjoy playing the game of Hopsco ...

  8. Windows Phone 自定义一个启动画面

    1.新建一个UserControl <UserControl x:Class="LoadingPage.PopupSplash" xmlns="http://sch ...

  9. 神兽保佑-代码无BUG

    ┏┓ ┏┓┏┛┻━━━┛┻┓┃ ┃ ┃ ━ ┃┃ ┳┛ ┗┳ ┃┃ ┃┃ ┻ ┃┃ ┃┗━┓ ┏━┛ ┃ ┃   神兽保佑 ┃ ┃   代码无BUG!       ┃ ┗━━━┓       ┃ ┣┓ ...

  10. 如何获取e.printStackTrace()的内容

    e.printStackTrace()通常是打印在控制台的,但是,有时候程序上线了需要看这个堆栈的内容就不容易了,一来生产环境打印的东西很多或者很少,二来有时候无法直接查看到,这个时候就需要把这些内容 ...