我想将列表中的多个单词与输入字符串匹配并返回匹配单词的列表。例如:
x = input("Enter a string?")
keywords= ["freeway", "doesn't turn on", "dropped", "got sick", "traffic jam", " car accident"]
输出:
Enter a string? there is a car accident on the freeway so that why I am late for the show.
the list of matched words are: car accident, freeway
我研究过,有些人建议使用 any(): if any(keyword in x for keyword in keyword) 但它只返回 true 或 false。我怎样才能返回匹配的单词列表。任何人都可以帮助我吗?
杨魅力
斯蒂芬大帝
相关分类