[英]How do I tell if a list of strings are found within a larger string?
I have a list of words (ie): 我有一个单词列表(即):
['bad', 'good', 'smart']
that I need to find which lines in a file that contain all those words within that line. 我需要找到文件中哪些行包含该行中的所有这些单词。 I've tried:
我试过了:
for line in file_text:
if [w for w in list] in line:
print(line)
However I get the following error: 但是我收到以下错误:
TypeError: 'in <string>' requires string as left operand, not list
What is an easy pythonic way of doing this? 什么是简单的pythonic方法?
One-Liner 一线
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.