If you only want to check for the presence of abc
in any string in the list, you could try
(如果您只想检查列表中任何字符串中是否存在abc
,可以尝试)
some_list = ['abc-123', 'def-456', 'ghi-789', 'abc-456']
if any("abc" in s for s in some_list):
# whatever
If you really want to get all the items containing abc
, use
(如果您真的想获取所有包含abc
的项目,请使用)
matching = [s for s in some_list if "abc" in s]
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…