码迷,mamicode.com
首页 > 编程语言 > 详细

Python3基础 用list()查看filter()返回的对象

时间:2017-01-16 13:02:42      阅读:1171      评论:0      收藏:0      [点我收藏+]

标签:通过   mat   window   cti   博客   code   val   use   result   

 镇场诗:
    诚听如来语,顿舍世间名与利。愿做地藏徒,广演是经阎浮提。
    愿尽吾所学,成就一良心博客。愿诸后来人,重现智慧清净体。
——————————————————————————————————————————

code:

#过滤器
#通过 过滤器 可以保留自己需要资源

value=filter(None,[1,-1,0,True,False,[1,0,True,False],[]])
valueList=list(value)

#有内容的列表被保留了下来,没有内容的列表被删除
#True被保留,Flase被删除
#0被删除 ,1被保留
print(valueList)

 


result:

============= RESTART: C:/Users/Administrator/Desktop/mytest7.py =============
[1, -1, True, [1, 0, True, False]]
>>> 

 

help:

>>> help(filter)
Help on class filter in module builtins:

class filter(object)
 |  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.
 |  
 |  Methods defined here:
 |  
 |  __getattribute__(self, name, /)
 |      Return getattr(self, name).
 |  
 |  __iter__(self, /)
 |      Implement iter(self).
 |  
 |  __new__(*args, **kwargs) from builtins.type
 |      Create and return a new object.  See help(type) for accurate signature.
 |  
 |  __next__(self, /)
 |      Implement next(self).
 |  
 |  __reduce__(...)
 |      Return state information for pickling.

>>> 

 


——————————————————————————————————————————
博文的精髓,在技术部分,更在镇场一诗。Python版本3.5,系统 Windows7。
Python是优秀的语言,值得努力学习。我是跟着小甲鱼视频教程学习的,推荐。
我是一个新手,所以如果博文的内容有可以改进的地方,甚至有错误的地方,请留下评论,我一定努力改正,争取成就一个良心博客。
注:此文仅作为科研学习,如果我无意中侵犯了您的权益,请务必及时告知,我会做出改正。

Python3基础 用list()查看filter()返回的对象

标签:通过   mat   window   cti   博客   code   val   use   result   

原文地址:http://www.cnblogs.com/jinlingzi/p/6289143.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!