我有一個名爲names
的字符串列表,我需要使用pattern
列表中的每個元素搜索names
列表中的每個元素。發現了一些指南,可以遍歷一個單獨的字符串,但不是字符串匹配另一個字符串元素列表的字符串元素搜索列表
a = [x for x in names if 'st' in x]
列表預先感謝您!
names = ['chris', 'christopher', 'bob', 'bobby', 'kristina']
pattern = ['st', 'bb']
所需的輸出:
a = ['christopher', 'bobby', 'kristina]
工作就像一個冠軍,並感謝您的解釋! – Christopher