我需要使用正则表达式和 Collection 找到多个匹配项(包含在列表中)。
我试过这段代码,但它显示空字典:
some_words_lst = ['caT.', 'Cat', 'Dog', 'paper', 'caty', 'London', 'loNdon','londonS']
words_to_find = ['cat', 'london']
r = re.compile('(?:.*{})'.format(i for i in words_to_find),re.IGNORECASE)
count_dictionary = {}
for item in some_words_lst:
if r.match(item):
count_dictionary['i']+=1
print(count_dictionary)
感谢帮助!
千巷猫影
相关分类