擅长:python、mysql、java
<p>你可以使用<code>range</code>,如果你找到一个<code>O</code>,你可以看看后面的</em>:</p>
<pre><code>text =[('Michael', 'PERSON'), ('Jordan', 'PERSON'), ("'s", 'O'), ('legacy', 'O'), ('in', 'O'), ('the', 'O'), ('90', 'O'), ("'s", 'O'), ('shows', 'O'), ('that', 'O'), ('he', 'O'), ('was', 'O'), ('the', 'O'), ('biggest', 'O'), ('player', 'O'), ('ever', 'O'), ('in', 'O'), ('the', 'O'), ('NBA', 'ORGANIZATION'), ('.', 'O')]
filtered_text = []
for idx in range(len(text)):
if text[idx][1] == "PERSON":
continue
if text[idx][1] == 'O' and idx > 0 and text[idx-1][1] == 'PERSON':
continue
filtered_text.append(text[idx][0])
sentence= " ".join(filtered_text)
print(sentence)
</code></pre>