python核心编程-filter函数
来源:互联网 发布:泛雅网络教学平台页面 编辑:程序博客网 时间:2024/05/17 07:11
#!/usr/bin/env python# -*- coding: UTF-8 -*-'''内建函数 filer()给定一个对象的序列和一个“过滤”函数,每个序列元素都通过这个过滤器进行筛选, 保留函数返回为真的的对象。def filter(bool_func, seq): filtered_seq = [] for eachItem in seq: if bool_func(eachItem): filtered_seq.append(eachItem) return filtered_seq'''''' 留下奇数''' from random import randintdef odd(n): return n%2allNums = []print '****',range(9) ##0-8for eachNum in range(9): allNums.append(randint(1, 99)) #1-99内产生随机数print allNumsprint filter(odd, allNums)
输出:
D:\Python27\test>func13.py**** [0, 1, 2, 3, 4, 5, 6, 7, 8][14, 20, 20, 17, 68, 25, 96, 61, 31][17, 25, 61, 31]D:\Python27\test>D:\Python27\test>D:\Python27\test>func13.py**** [0, 1, 2, 3, 4, 5, 6, 7, 8][9, 8, 83, 44, 19, 70, 71, 37, 23][9, 83, 19, 71, 37, 23]D:\Python27\test>
0 0
- python核心编程-filter函数
- python核心编程-filter函数重构
- python核心编程-filter重构2
- [Python]核心编程之函数
- python核心编程-函数调用
- python核心编程-诊断函数
- python核心编程-map函数
- python核心编程-reduce函数
- python核心编程-partial函数
- Python核心编程多种方法实现过滤filter()
- python核心编程-函数-内嵌函数
- python函数式编程 map、reduce、filter
- Python函数式编程之filter
- 《Python核心编程》函数---学习笔记
- python核心编程-函数返回值
- python核心编程-函数参数传递
- python核心编程-函数-装饰器
- python核心编程-默认函数对象参数
- Git基本的工作流程
- Shiro介绍(二):从简单的认证开始
- CSU 1556 快速幂
- 错误总结:ERROR:ITMS-90032
- Qt 创建上下文菜单
- python核心编程-filter函数
- poj Repeater 3768 (模拟&&dfs) 好题
- HDOJ 5289 Assignment 【RMQ 二分 || 单调队列】
- android html解析
- cmd正则表达式批量重命名
- 容器的同步控制与只读设置JAVA133
- poj Fractal 2083 (模拟&&dfs)
- CSU 1553 线段树+尺取法
- java设计模式(四)—工厂模式