![](/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.