#
# def use_filer(l):
#
# # 过滤偶数
# rest = filter(lambda n: n % 2 != 0, l)
# return rest
#
# if __name__ == '__main__':
# l = [1,2,3,4,5,6,7,8,9,10,11]
# rest = use_filer(l)
# # [1, 3, 5, 7, 9, 11]
# print(list(rest))
#
#
#
# def pow_number(l):
# # 返回 数据的立方
# rest_list = []
# for x in l:
# rest_list.append(x * x * x)
# return rest_list
#
# def f(n):
# return n * n * n
#
# def pow_num_use_map(l):
# return map(f,l)
#
#
# def pow_num_use_lambda(l):
# return map(lambda n:n * n * n,l)
#
#
#
# if __name__ == '__main__':
# l = [1,2,3,4,5,6,7,8,9,10]
# rest = pow_number(l)
# # [1, 8, 27, 64, 125, 216, 343, 512, 729, 1000]
# print (rest)
# print ('--------------------------')
# rest_map = pow_num_use_map(l)
# # [1, 8, 27, 64, 125, 216, 343, 512, 729, 1000]
# print (list(rest_map))
# print ('--------------------------')
# rest_lambda = pow_num_use_lambda(l)
# # [1, 8, 27, 64, 125, 216, 343, 512, 729, 1000]
# print (list(rest_lambda)) # 求和
def get_sum(l):
rest = 0
for i in l:
rest += i
return rest def get_sum_use_py(l):
return sum(l) from functools import reduce
def f(m,n):
return m + n def get_sum_use_reduce(l):
return reduce(f,l) def get_sum_use_lamdad(l):
return reduce(lambda m , n : m + n,l) if __name__ == '__main__':
l = [1,2,4,6,7,8,9]
rest = get_sum(l)
# 37
print (rest)
print('------------------')
rest_py = get_sum_use_py(l)
print (rest_py)
print('------------------')
rest_reduce = get_sum_use_reduce(l)
print (rest_reduce)
print('------------------')
rest_lamdad = get_sum_use_lamdad(l)
print (rest_lamdad)

python 高阶函数 lamdad reduce map的更多相关文章

  1. Python高阶函数_map/reduce/filter函数

    本篇将开始介绍python高阶函数map/reduce/filter的用法,更多内容请参考:Python学习指南 map/reduce Python内建了map()和reduce()函数. 如果你读过 ...

  2. python 高阶函数学习, map、reduce

    一个函数可以接收另一个函数作为参数,这样的函数叫做高阶函数. 函数map(): map()函数接收两个参数,一个是函数,一个是Iterable, map把函数作用于序列的每一个元素,并把结果作为Ite ...

  3. python 高阶函数之 reduce

    1.正常写法 >>> from functools import reduce >>> def fn(x, y): ... return x * 10 + y .. ...

  4. Python高阶函数map、reduce、filter、sorted的应用

    #-*- coding:utf-8 -*- from selenium import webdriver from selenium.webdriver.support.wait import Web ...

  5. 高阶函数概念以及map/filter/reduce

    什么样的函数叫高阶函数:map(func, *iterables) --> map object 条件:1.函数接受函数作为参数 2.函数的返回值中包含函数 num_l = [1,2,3,4,5 ...

  6. 用一个简单的例子来理解python高阶函数

    ============================ 用一个简单的例子来理解python高阶函数 ============================ 最近在用mailx发送邮件, 写法大致如 ...

  7. Python高阶函数和匿名函数

    高阶函数:就是把函数当成参数传递的一种函数:例如 注解: 1.调用add函数,分别执行abs(-8)和abs(11),分别计算出他们的值 2.最后在做和运算 map()函数 python内置的一个高阶 ...

  8. python高阶函数的使用

    目录 python高阶函数的使用 1.map 2.reduce 3.filter 4.sorted 5.小结 python高阶函数的使用 1.map Python内建了map()函数,map()函数接 ...

  9. python 高阶函数之filter

    前文说到python高阶函数之map,相信大家对python中的高阶函数有所了解,此次继续分享python中的另一个高阶函数filter. 先看一下filter() 函数签名 >>> ...

随机推荐

  1. Linux+CLion+树莓派远程编译时,Cmake编译出现undefined reference to `vtable for MainWindow'的解决办法

    在win+CLion上进行远程qt开发时碰到以下错误: 错误提示: undefined reference to `vtable for MainWindow' 原因:源文件的目录结构有问题?? 解决 ...

  2. Elasticsearch学习笔记-Delete By Query API

    记录关于Elasticsearch的文档删除API的学习 首先官网上Document APIs介绍了 Delete API 和Delete By Query API. Delete API可以通过指定 ...

  3. sftp winscp

    https://stackoverflow.com/questions/16150152/secure-ftp-using-windows-batch-script First, make sure ...

  4. Exponentiation(求高精度幂)

    Exponentiation Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 175340   Accepted: 42341 ...

  5. 慎用String.intern()作为synchronized的对象锁

    https://www.cnblogs.com/yhlx/p/3498387.html

  6. RDS数据库全量恢复方案

    一.全量恢复 恢复最近的快照,将快找之前的数据全量恢复 二.增量恢复 下载对应的binlog日志导入到数据库 三.还没有备份的binlog日志获取方法 首先连接 RDS for MySQL 后查看当前 ...

  7. 机器学习 - 算法 - 集成算法 - 分类 ( Bagging , Boosting , Stacking) 原理概述

    Ensemble learning - 集成算法 ▒ 目的 让机器学习的效果更好, 量变引起质变 继承算法是竞赛与论文的神器, 注重结果的时候较为适用 集成算法 - 分类 ▒ Bagging - bo ...

  8. Swift开源parser

    https://www.prowidesoftware.com/products/core https://github.com/prowide/prowide-core-examples/blob/ ...

  9. 小D课堂 - 新版本微服务springcloud+Docker教程_5-06 高级篇幅之深入源码

    笔记 6.高级篇幅之深入源码剖析Hystrix降级策略和调整     简介:源码分析Hystrix降级策略和调整 1.查看默认讲解策略 HystrixCommandProperties        ...

  10. 一百零三:CMS系统之使用sweetalert提示框优化返回结果

    在base模板中引用 在修改密码的js中使用 $(function () { $('#submit').click(function (evnet) { evnet.preventDefault(); ...