![](/img/trans.png)
[英]How do I match exact strings from a list to a larger string taking white spaces into account?
[英]How do I tell if a list of strings are found within a larger string?
我有一个单词列表(即):
['bad', 'good', 'smart']
我需要找到文件中哪些行包含该行中的所有这些单词。 我试过了:
for line in file_text:
if [w for w in list] in line:
print(line)
但是我收到以下错误:
TypeError: 'in <string>' requires string as left operand, not list
什么是简单的pythonic方法?
一线
for line in file_text:
[line for w in list if w in line and w == 'smart']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.