1、判断列表(list)中所有元素是否在集合(set)中
list_string = ['big', 'letters'] string_set = set(['hello', 'hi', 'big', 'cccc', 'letters', 'anotherword']) result = all([word in string_set for word in list_string])
#结果是True
2、判断列表中的每个字符串元素是否含另一个列表的所有字符串元素中
list_string= ['big', 'letters']
list_text = ['hello letters', 'big hi letters', 'big superman letters']
result = all([word in text for word in list_string for text in list_text])
#结果是False,因为'big'不在'hello letters'中。
3、如果要获取符合条件字符串,可以用filter
list_string= ['big', 'letters']
list_text = ['hello letters', 'big hi letters', 'big superman letters']
all_words = list(filter(lambda text: all([word in text for word in list_string]), list_text )) print(all_words)
#['big hi letters', 'big superman letters']