博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python3 filter函数使用
阅读量:2047 次
发布时间:2019-04-28

本文共 307 字,大约阅读时间需要 1 分钟。

  1. 返回filter对象,其中包含对其执行函数时结果为真的所有元素

  2. filter(func,sep)

def use_filter(l):    """    获取指定列表/元组中的奇数    :param l: list/tuple 要过滤的数据    :return: 过滤好的奇数列表    """    rest = filter(lambda n:n%2 != 0,l)    return restif __name__ == "__main__":    l = [1,2,3,4,5,6,7,8,9,10,11]    rest = use_filter(l)    print(list(rest))

转载地址:http://scmof.baihongyu.com/

你可能感兴趣的文章
Leetcode C++《热题 Hot 100-17》461.汉明距离
查看>>
Leetcode C++《热题 Hot 100-18》538.把二叉搜索树转换为累加树
查看>>
Leetcode C++《热题 Hot 100-19》543.二叉树的直径
查看>>
Leetcode C++《热题 Hot 100-21》581.最短无序连续子数组
查看>>
Leetcode C++《热题 Hot 100-22》2.两数相加
查看>>
Leetcode C++《热题 Hot 100-23》3.无重复字符的最长子串
查看>>
Leetcode C++《热题 Hot 100-24》5.最长回文子串
查看>>
Leetcode C++《热题 Hot 100-26》15.三数之和
查看>>
Leetcode C++《热题 Hot 100-27》17.电话号码的字母组合
查看>>
Leetcode C++《热题 Hot 100-28》19.删除链表的倒数第N个节点
查看>>
Leetcode C++《热题 Hot 100-29》22.括号生成
查看>>
Leetcode C++《热题 Hot 100-30》31.下一个排列
查看>>
Leetcode C++《热题 Hot 100-40》64.最小路径和
查看>>
Leetcode C++《热题 Hot 100-41》75.颜色分类
查看>>
Leetcode C++《热题 Hot 100-42》78.子集
查看>>
Leetcode C++《热题 Hot 100-43》94.二叉树的中序遍历
查看>>
Leetcode C++ 《第175场周赛-1 》5332.检查整数及其两倍数是否存在
查看>>
Leetcode C++ 《第175场周赛-2 》5333.制造字母异位词的最小步骤数
查看>>
Leetcode C++ 《第175场周赛-3》1348. 推文计数
查看>>
Leetcode C++《热题 Hot 100-44》102.二叉树的层次遍历
查看>>