Python 检查列表中的字符串中是否有单词

Python 检查列表中的字符串中是否有单词,python,string,list,python-2.7,Python,String,List,Python 2.7,所以说我有 list = ['I am blue', 'I am red', 'I am not blue', 'I am green'] 有没有办法创建一个新的列表,以便它只包含“list”中包含单词“blue”的条目(并且忽略该字符串的其他部分)?i、 e 然后我需要检查“蓝名单”中的条目数量,但我可以用 len(blue_list) 谢谢 使用列表理解,同时重命名列表,使其不会影响内置的: l = ['I am blue', 'I am red', 'I am not blue', '

所以说我有

list = ['I am blue', 'I am red', 'I am not blue', 'I am green']
有没有办法创建一个新的列表,以便它只包含“list”中包含单词“blue”的条目(并且忽略该字符串的其他部分)?i、 e

然后我需要检查“蓝名单”中的条目数量,但我可以用

len(blue_list)

谢谢

使用列表理解,同时重命名列表,使其不会影响内置的:

l = ['I am blue', 'I am red', 'I am not blue', 'I am green']
blue_list = [phrase for phrase in l if 'blue' in phrase]

字符串包含和单词包含是非常不同的问题。“蓝色”是“清洗剂”一词的一部分,例如:你想不想去除“清洗剂有效”?
l = ['I am blue', 'I am red', 'I am not blue', 'I am green']
blue_list = [phrase for phrase in l if 'blue' in phrase]