【发布时间】:2021-01-13 03:09:39
【问题描述】:
我有以下搜索列表,可用于根据更大的列表列表搜索其中的任何项目。我希望结果是完整的子列表,但我似乎只得到项目本身。
search_list = ['a', 'b', 'x']
list_of_lists = [['axh', 'opp'], ['l n', '3b v'], ['09,8', 'cdj l', 'sd9 c']
new_lst=[]
for z in list_of_lists:
yll = [x for x in z if any(w in x for w in search_list)]
n_lst.append(yll)
new_lst 的输出:
new_lst = [['a xh'], ['3 b v'], []]
我是在获得此输出之后显示结果列表中与 search_list
中的任何项目匹配的所有项目[['a xh', 'opp'], ['l n', '3b v'], []]
任何建议或提示将不胜感激。
谢谢
【问题讨论】:
标签: python-3.x list list-comprehension