[英]How to find all occurrences of a list of strings in a string and return a list of list of int in python?
[英]How to find if all the list of strings exits in another list in Python
我正在嘗試尋找一種方法來查找列表中的所有元素是否存在於另一個列表中。 嘗試了以下代碼,但仍然無法解決。
#!/usr/intel/bin/python2.7
# Global Import Variables
import Tkinter, Tkconstants, tkFileDialog
import warnings
import os.path
search_line = []
search_line.append('APPLE')
search_line.append('MANGO_REQUEST')
search_line.append('SeaPort')
line = []
linez = "helo how are APPLE helloo.log.gz you MANGO_REQUEST life is cool and as usual SeaPort"
linez = linez.split()
print linez
print search_line
print linez
if all(x in search_line for x in linez):
print "final result"
print linez
但它從未滿足方程式。 有什么想念的嗎? 請分享您的想法。
謝謝 !
問題在於您的狀況:
if all(x in search_line for x in linez):
您正在檢查linez
所有“單詞”是否都在search_line
列表中,這顯然是False
,您想用另一種方法來做:
if all(x in linez for x in search_line):
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.