擅长:python、mysql、java
<p>您可以尝试使用集合,特别是<code>set.isdisjoint</code>。检查happy tweet中的令牌集是否与<code>sad_set</code>不相交。如果是这样,它肯定属于<code>happy</code>:</p>
<pre><code>happy_set = set([":)",":-)","=)",":D",":-D","=D"])
sad_set = set([":(",":-(","=("])
# happy is your existing set of potentially happy tweets. To remove any tweets with sad tokens...
happy = [tweet for tweet in happy if sad_set.isdisjoint(set(tweet.split()))]
</code></pre>