擅长:python、mysql、java
<p>我认为只指定“特殊”两个单词标记更实际。你知道吗</p>
<pre><code>special_words = ['Main Course', 'Something Special']
sentence = 'Starter Main Course Dessert Something Special Date'
words = sentence.split(' ')
for i in range(len(words) - 1):
try:
idx = special_words.index(str(words[i]) + ' ' + words[i+1])
words[i] = special_words[idx]
words[i+1] = None
except ValueError:
pass
words = list(filter(lambda x: x is not None, words))
print(words)
</code></pre>