首页 > 编程语言 >如何用python判断字符串包含多个字符串中的一个或多个?

如何用python判断字符串包含多个字符串中的一个或多个?

时间:2022-12-21 22:25:36浏览次数:47  
标签:多个 python sum keywordslist Tom 字符串 math

https://blog.csdn.net/weixin_42445362/article/details/109819677

p = "Tom is a boy,Lucy is a girl,Tom like math and Lucy like english!"

keywordslist= ["english","math","history","laws"]

sum([1 if w in p and w else 0 for w in keywords.split(',')])

sum([1 if w in p and w else 0 for w in keywordslist])

输出2

标签:多个,python,sum,keywordslist,Tom,字符串,math
From: https://www.cnblogs.com/Cookie-Jing/p/16997338.html

相关文章