回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我有下面的元组</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')]
</code></pre>
<p>原话是“迈克尔乔丹在90年代留下的遗产表明他是NBA有史以来最伟大的球员。”</p>
<p>我需要删除分类为“PERSON”的元素</p>
<p>我就这么做了</p>
<pre><code>new_text = [x for x in text if x[1] != "PERSON"]
sentence= " ".join(x[0] for x in new_text)
print(sentence)
</code></pre>
<p>我得到的结果是</p>
<pre><code>'s legacy in the 90 's shows that he was the biggest player ever in the NBA .
</code></pre>
<p>请注意开头的<code>"'s"</code>。你知道吗</p>
<p>现在我被卡住了,因为我需要在成为<code>"PERSON"</code>之前删除以元素为条件的“'s”元素。在这个例子中有2<code>"'s"</code>,但我只想删除紧跟在<code>"PERSON"</code>后面的那个。有什么建议吗?你知道吗</p>
<p>谢谢你的意见。你知道吗</p>