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

上传:zhojie79710 浏览: 44 推荐: 0 文件:PDF 大小:28.13KB 上传时间:2020-12-31 11:35:05 版权申诉
使用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
上传资源
用户评论