python过滤函数filter用法

微信扫一扫,分享到朋友圈

python过滤函数filter用法
收藏 01

过滤字数大于3的列表

def get_content_wordnumber(html):
    text =re.sub('[\s+\.\!\/_,$%^*(+\"\']+|[+——!,::。?、~@#¥%……&*()“”《》]','',html)
    text2 = re.sub('<[^>]*?>', '', text)
    words_number = len(text2)
    return words_number


a1 = '<p>你好呀你好呀你好呀你好呀你好呀你好呀</p>'
a2 ='你好呀你好呀'
a3 ='你好呀你好呀你好呀你好呀'
a4 ='你好呀你好呀你好呀你好呀你好呀你好呀你好呀你好呀'
# print(get_content_wordnumber(a1))
w = [a1,a2,a3,a4]
cs1 = filter(lambda x:get_content_wordnumber(x)>3,w)
print(list(cs1))

 

一个热爱互联网的咸鱼
下一篇

python处理纯文本内容添加html标签

你也可能喜欢

1 条评论

  1. I was excited to uncover this website. I need to to thank you for ones time for this particularly fantastic read!! I definitely really liked every part of it and i also have you bookmarked to look at new things in your site.

发表评论

您的电子邮件地址不会被公开。 必填项已用 * 标注

提示:点击验证后方可评论!

插入图片

热门

    抱歉,30天内未发布文章!
返回顶部