zoukankan      html  css  js  c++  java
  • python3 内置函数 filter()

    filter(function or None, iterable) --> filter object

    Return an iterator yielding those items of iterable for which function(item)
    is true. If function is None, return the items that are true.

    函数有两个参数,第一个可以为一个函数,或者None,第二个参数为一个可迭代对象

    保返回真值(非零,非空)返回值为一个filter object

    1 ls = [1, 0 -1, 3]
    2 
    3 l =(filter(None,ls))
    4 print(l)
    5 
    6 <filter object at 0x0000023036E7A390>
    filter1

     这个filter object 是个可迭代对象

     1 ls = [1, 0 -1, 3]
     2 
     3 def t(x ):
     4     if x > 0:
     5         return True
     6     else:
     7         return False
     8     
     9 l =(filter(t,ls))
    10 for i in l:
    11     print(i)
    12 
    13 1
    14 3
    filter2
  • 相关阅读:
    js字符串空格和换行
    python resources
    -eous
    英语资源网站
    -iatry 没病走两步
    book corpus
    epub converters
    brainstorm detain
    craftsman
    parachute
  • 原文地址:https://www.cnblogs.com/Andy963/p/5320907.html
Copyright © 2011-2022 走看看