更新时间:2022-11-11 12:27:30
如果您只想检查列表中任何字符串中是否存在abc
,您可以尝试
If you only want to check for the presence of abc
in any string in the list, you could try
some_list = ['abc-123', 'def-456', 'ghi-789', 'abc-456']
if any("abc" in s for s in some_list):
# whatever
如果你真的想得到所有包含abc
的项目,使用
If you really want to get all the items containing abc
, use
matching = [s for s in some_list if "abc" in s]