您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
三六零分类信息网 > 张掖分类信息网,免费分类信息发布

Python数组条件过滤filter函数使用示例

2025/9/21 12:22:18发布25次查看
使用filter函数,实现一个条件判断函数即可。
比如想过滤掉字符串数组中某个敏感词,示范代码如下:
#filter out some unwanted tags def passed(item): try: return item != techbrood #can be more a complicated condition here except valueerror: return false org_words = [[this,is],[demo,from],[techbrood]] words = [filter(passed, item) for item in org_words]
注意python2.x和python3.x对于filter/map的处理并不兼容,在python2.x里面直接返回一个list.
在python3.x里返回一个iterable对象,比如,后面那串数字是对象引用地址。
可以使用list(words)转换。
张掖分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product