import re
words = ["AMALGAMATED", "AMMONIATED", "CIRCUMAMBULATED", "COMMENTATED",
"TAMTAM", "BLUB", "HOUSE", "SOMETHING"]
filter = "mmt"
regex = re.compile(".*".join(filter), re.IGNORECASE)
filtered_words = [word for word in words if regex.search(word)]
print(*filtered_words, sep="\n")
您可以生成一个动态正则表达式模式并基于该模式筛选列表:
See this code running on ideone.com
相关问题 更多 >
编程相关推荐