擅长:python、mysql、java
<p>根据更新后的问题,很难判断每个关键元素的第一个单词是否是值中的单词。这个例子太宽泛了,所以我考虑到了这一点,并更新了我的答案。你知道吗</p>
<pre><code>category = []
keys = ['start', 'steak well done', 'come on', 'He is going', 'c', 'D', 'm', 'l', 'o']
values = ['well', 'going', 'come', 'D']
for key in keys:
if ' ' in key:
for value in values:
if value in key:
category.append(value)
continue
if key in values:
category.append (key)
continue
else:
category.append ('other')
category
['other', 'well', 'come', 'going', 'other', 'D', 'other', 'other', 'other']
</code></pre>