获取python中包含子列表的元素

获取python中包含子列表的元素,python,list,substring,sublist,Python,List,Substring,Sublist,我正在尝试搜索一个大的注释列表,并返回带有子列表中单词的注释 sub = 'body' submore = ['Olive', 'Personally', 'Hiding'] submore = [s.lower() for s in submore] print submore for s in submore: print "\n".join(s.lower() for s.lower(0 text.take(1000) if submore.lower(

我正在尝试搜索一个大的注释列表,并返回带有子列表中单词的注释

sub = 'body'
submore = ['Olive', 'Personally', 'Hiding']
submore = [s.lower() for s in submore]
print submore


for s in submore:
    print "\n".join(s.lower() for s.lower(0 text.take(1000) if 
           submore.lower() in s.lower())
如果文本列表中的一条评论包含“我个人愿意”这句话,它会打印出整个评论


上面的代码适用于字符串,但不适用于列表。任何帮助都将不胜感激

将理解列表和任何内置函数结合起来:

comments = [...arbitrary list of comments...]
comments = [c.lower() for c in comments] # put all comments in lowercase
words = [...arbitrary list of words...]
words = [w.lower() for w in words] # same for words

matches = [c for c in comments if any(w in c for w in words)] 

不,您发布的代码实际上不适用于字符串或列表。存在大量语法错误和未定义的变量。请发一封信。