python filter函数
来源:互联网 发布:新浪网的域名和ip地址 编辑:程序博客网 时间:2024/04/27 10:17
Python内建的filter()
函数用于过滤序列。
例如,在一个list中,删掉偶数,只保留奇数,可以这么写:
def is_odd(n): return n % 2 == 1list(filter(is_odd, [1, 2, 4, 5, 6, 9, 10, 15]))# 结果: [1, 5, 9, 15]
把一个序列中的空字符串删掉,可以这么写:
def not_empty(s): return s and s.strip()list(filter(not_empty, ['A', '', 'B', None, 'C', ' ']))# 结果: ['A', 'B', 'C']
阅读全文
0 0
- python 常用函数 filter
- python小点心--filter函数
- Python filter()函数
- python filter函数
- python中filter()函数
- python中的filter()函数
- python-内置函数filter()
- python中的filter函数
- python filter函数
- python中filter()函数
- Python 内置函数 filter()
- python 中filter()函数
- python中filter()函数
- python: filter函数
- python中filter函数
- python中filter()函数
- Python filter()函数
- Python---filter()函数
- 手术及切口分类与伤口愈合分级以及ASA麻醉分级
- 深入详解SetHash的元素为什么要重写hashCode和equals方法
- C#——面向对象——事件和委托——事件
- vue.js学习05之基于$.ajax的跨越增删改查
- Dynamic Web Module 3.0 requires Java 1.6 or newer
- python filter函数
- 【微信小编】关联规则图
- ThinkPHP胜出Laravel 近4倍,主流框架性能测试
- 排序问题专题总结
- 同时点击手势深度优化处理 setExclusiveTouch
- mybatis批量操作
- FAFU OJ 删除子串
- AsyncHttpClient上传文件到服务器 注意6.0权限
- LeetCode 287. Find the Duplicate Number