Python 3.x Python检查列表中是否有给定的多个子字符串

Python 3.x Python检查列表中是否有给定的多个子字符串,python-3.x,Python 3.x,我需要检查列表中是否有几个子字符串。我发现了以下代码。但它只需要一个字符串 test_list = ['GeeksforGeeks', 'Geeky', 'Computers', 'Algorithms'] subs = 'Geek' res = [i for i in test_list if subs in i] print ("All strings with given substring are : " + str(res)) 如果我想找到两个子串,比如“Geek”和“Algo

我需要检查列表中是否有几个子字符串。我发现了以下代码。但它只需要一个字符串

test_list = ['GeeksforGeeks', 'Geeky', 'Computers', 'Algorithms'] 
subs = 'Geek'
res = [i for i in test_list if subs in i] 
print ("All strings with given substring are : " + str(res)) 

如果我想找到两个子串,比如“Geek”和“Algo”,我该怎么办

它将获得所有匹配项,因为Geek是两倍,匹配项将包含两个Geek

import re 
test_list = ['GeeksforGeeks', 'Geeky', 'Computers', 'Algorithms'] 
test_list = ' '.join(test_list)
subs = 'Geek,Algo'
matches = re.findall(r'Geek|Algo', test_list, re.IGNORECASE)
print(set(matches)
print(set((matches))
如果你想变得独一无二
只要加上这一行

就可以回答你的问题了吗?通过链接将问题读为
str=“a123”
as
str=['a','1','2','3']
。是的。非常感谢。我想我必须把关键词分开。