【python】filter()
来源:http://www.jb51.net/article/54316.htm
filter函数:
filter()函数可以对序列做过滤处理,就是说可以使用一个自定的函数过滤一个序列,把序列的每一项传到自定义的过滤函数里处理,并返回结果做过滤。最终一次性返回过滤后的结果。
filter()函数有两个参数:
第一个,自定函数名,必须的
第二个,需要过滤的列,也是必须的
DEMO
需求,过滤大于5小于10的数:
# coding=utf8
# 定义大于5小于10的函数
def guolvhanshu(num):
if num>5 and num<10:
return num # 定义一个序列
seq=(12,50,8,17,65,14,9,6,14,5) # 使用filter函数
result=filter(guolvhanshu,seq) # (8,9,6)
print result
执行结果
(8, 9, 6)
【python】filter()的更多相关文章
- 【python】filter,map,reduce和lambda函数介绍
filter(function, iterable)map(function, iterable)reduce(function, sequence) filter将 function依次作用于ite ...
- 【Python②】python之首秀
第一个python程序 再次说明:后面所有代码均为Python 3.3.2版本(运行环境:Windows7)编写. 安装配置好python后,我们先来写第一个python程序.打开IDLE (P ...
- 【python】多进程锁multiprocess.Lock
[python]多进程锁multiprocess.Lock 2013-09-13 13:48 11613人阅读 评论(2) 收藏 举报 分类: Python(38) 同步的方法基本与多线程相同. ...
- 【python】SQLAlchemy
来源:廖雪峰 对比:[python]在python中调用mysql 注意连接数据库方式和数据操作方式! 今天发现了个处理数据库的好东西:SQLAlchemy 一般python处理mysql之类的数据库 ...
- 【python】getopt使用
来源:http://blog.chinaunix.net/uid-21566578-id-438233.html 注意对比:[python]argparse模块 作者:limodou版权所有limod ...
- 【Python】如何安装easy_install?
[Python]如何安装easy_install? http://jingyan.baidu.com/article/b907e627e78fe146e7891c25.html easy_instal ...
- 【Python】 零碎知识积累 II
[Python] 零碎知识积累 II ■ 函数的参数默认值在函数定义时确定并保存在内存中,调用函数时不会在内存中新开辟一块空间然后用参数默认值重新赋值,而是单纯地引用这个参数原来的地址.这就带来了一个 ...
- 【Python】-NO.97.Note.2.Python -【Python 基本数据类型】
1.0.0 Summary Tittle:[Python]-NO.97.Note.2.Python -[Python 基本数据类型] Style:Python Series:Python Since: ...
- 【Python】-NO.99.Note.4.Python -【Python3 条件语句 循环语句】
1.0.0 Summary Tittle:[Python]-NO.99.Note.4.Python -[Python3 条件语句 循环语句] Style:Python Series:Python Si ...
随机推荐
- abstract 类也可以继承 实体类
public class BaseReq { public String UserId { get; set; } public BaseReq() { } } public abstract cla ...
- std::thread
std::shared_ptr<std::thread> m_spThread; m_spThread.reset(new std::thread(std::bind(&GameS ...
- Chord算法
转自:http://blog.csdn.net/wangxiaoqin00007/article/details/7374833 虽然网上搜索CHord,一搜一大堆,但大多讲得不太清楚明白.今天发现一 ...
- Why The Golden Age Of Machine Learning is Just Beginning
Why The Golden Age Of Machine Learning is Just Beginning Even though the buzz around neural networks ...
- 字符串匹配的KMP算法详解及C#实现
字符串匹配是计算机的基本任务之一. 举例来说,有一个字符串"BBC ABCDAB ABCDABCDABDE",我想知道,里面是否包含另一个字符串"ABCDABD" ...
- meclipse中project facet问题
meclipse中project facet问题 (2012-02-14 14:59:48) 转载▼ 标签: 杂谈 分类: 技术 一般出现在从别处import的项目上,只有项目文件夹上有红叉,其他地方 ...
- JavaScript 技巧总结
日期1. 日期时间戳 +new Date() = new Date().getTime() 数组1. 类数组转数组 var arr = Array.prototype.slice.call(argum ...
- spark1.6配置sparksql 的元数据存储到postgresql中
1:首先配置hive-site.xml <configuration> <property> <name>javax.jdo.option.ConnectionUR ...
- $key 的用法
<?php $attr=array("a","b","c","d"); //$key,默认是主键值,$value, ...
- [Effective JavaScript 笔记]第61条:不要阻塞I/O事件队列
js程序是构建在事件之上的.输入可能来自不同的外部源.在一些语言中,我们习惯地编写代码来等待某个特定的输入. var text=downloadSync('http://example.com/fil ...