python /编程新手,所以不太清楚如何表达这个......
我要做的是:输入一个句子,找到输入句子的所有匹配项和一组存储的句子/字符串,并返回匹配字符串的最长组合。
我认为答案与正则表达式有关,但我还没有开始这些,如果我不需要的话也不想这样做。
我的问题:正则表达式是解决这个问题的方法吗?或者有没有办法在不导入任何东西的情况下做到这一点?
如果它可以帮助您理解我的问题/想法,这是我正在尝试做的伪代码:
input = 'i play soccer and eat pizza on the weekends'
focus_word = 'and'
ss = [
'i play soccer and baseball',
'i eat pizza and apples',
'every day i walk to school and eat pizza for lunch',
'i play soccer but eat pizza on the weekend',
]
match = MatchingFunction(input, focus_word, ss)
# input should match with all except ss[3]
ss[0]match= 'i play soccer and'
ss[1]match = 'and'
ss[2]match = 'and eat pizza'
#the returned value match should be 'i play soccer and eat pizza'