error in code involving while loop and removing items from string
<p>I have a code that downloads tweets and I am trying to sort through it labeling it as positive or negative each time i label a tweet I want to remove it from the string so I won't be asked to label it again here is my code so far</p>

<pre><code>while True:
    if len(tweet_list) == 0:
        break
    else:
        tweet1= (np.random.choice(tweet_list))
        print tweet1
        judge = input("1 pos, 2 neg 3 skip: ")
        if judge == 1:
            tweet_pos.append(tweet1)
            tweet_list.remove(tweet1)
        if judge == 2:
            tweet_neg.append(tweet1)
            tweet_list.remove(tweet1)
</code></pre>

<p>after I label the second tweet I am given this error</p>

<pre><code>ValueError: list.remove(x): x not in list
</code></pre>

<p>Make an empty list outside out of your while loop like this:</p>

<pre><code>tweet_pos = []
tweet_neg = []
alreadySeen = []
</code></pre>

<p>Revise your first <code>if</code> statement in your code like so:</p>

<pre><code>if len(alreadySeen) == 20:
        break
</code></pre>

<p>Make sure when you're displaying the tweets, you want to use <code>tweet1.text</code>. Sometimes it doesn't encode the message properly, or at all, so you can use <code>tweet1.text.encode('utf-8')</code>. Then each time you make a judgment, add that tweet to the <code>alreadySeen</code> list. Henceforth, check it to see if it is already in that list, and if it is, keep getting a random tweet until it hasn't already been seen.</p>

<pre><code>if tweet1 not in alreadySeen:
        print tweet1.text.encode('utf-8')
        judge = input("1 pos, 2 neg, 3 skip: ")
        if judge == 1:
            tweet_pos.append(tweet1)
        elif judge == 2:
            tweet_neg.append(tweet1)
        alreadySeen.append(tweet1)
</code></pre>

<p>Finally, for confirmation, you can output the results by iterating through each tweet in <code>tweet_pos</code> and <code>tweet_neg</code> and print each tweet out just as you did earlier.</p>

<pre><code>print "My positive tweets: "
for pos in tweet_pos:
    print pos.text.encode('utf-8')

print "My negative tweets: "
for neg in tweet_neg:
    print neg.text.encode('utf-8')
</code></pre>

<p>Hope this helped.</p>

python string while-loop tweepy