더 큰 목록 목록에 대해 항목을 검색하는 데 사용할 다음 검색 목록이 있습니다. 결과가 완전한 하위 목록이되기를 원하지만 항목 자체 만 가져 오는 것 같습니다.
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'], []]
어떤 제안이나 조언을 주시면 감사하겠습니다.
감사
append
일치 new_list
하는 문자 가있는 경우 하위 목록search_list
search_list = ['a', 'b', 'x']
list_of_lists = [['axh', 'opp'], ['l n', '3b v'], ['09,8', 'cdj l', 'sd9 c']]
new_list = []
for sub in list_of_lists:
for l in sub:
if any(w in l for w in search_list):
new_list.append(sub)
print(new_list)
# Output
# [['axh', 'opp'], ['l n', '3b v']]
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다