TypeError: 'in ' requires string as left operand, not generator in Python
<p>I'm trying to parse tweets data.</p>

<p>My data shape is as follows:</p>

<pre><code>59593936 3061025991 null null &lt;d&gt;2009-08-01 00:00:37&lt;/d&gt; &lt;s&gt;&amp;lt;a href="http://help.twitter.com/index.php?pg=kb.page&amp;amp;id=75" rel="nofollow"&amp;gt;txt&amp;lt;/a&amp;gt;&lt;/s&gt; &lt;t&gt;honda just recalled 440k accords...traffic around here is gonna be light...win!!&lt;/t&gt; ajc8587 15 24 158 -18000 0 0 &lt;n&gt;adrienne conner&lt;/n&gt; &lt;ud&gt;2009-07-23 21:27:10&lt;/ud&gt; &lt;t&gt;eastern time (us &amp;amp; canada)&lt;/t&gt; &lt;l&gt;ga&lt;/l&gt;
22020233 3061032620 null null &lt;d&gt;2009-08-01 00:01:03&lt;/d&gt; &lt;s&gt;&amp;lt;a href="http://alexking.org/projects/wordpress" rel="nofollow"&amp;gt;twitter tools&amp;lt;/a&amp;gt;&lt;/s&gt; &lt;t&gt;new blog post: honda recalls 440k cars over airbag risk http://bit.ly/2wsma&lt;/t&gt; madcitywi 294 290 9098 -21600 0 0 &lt;n&gt;madcity&lt;/n&gt; &lt;ud&gt;2009-02-26 15:25:04&lt;/ud&gt; &lt;t&gt;central time (us &amp;amp; canada)&lt;/t&gt; &lt;l&gt;madison, wi&lt;/l&gt;
</code></pre>

<p>I want to get the total numbers of tweets and the numbers of keyword related tweets. I prepared the keywords in text file. In addition, I wanna get the tweet text contents, total number of tweets which contain mention(@), retweet(RT), and URL (I wanna save every URL in other file).</p>

<p>So, I coded like this.</p>

<pre><code>import time
import os

total_tweet_count = 0
related_tweet_count = 0
rt_count = 0
mention_count = 0
URLs = {}

def get_keywords(filepath, mode):
    with open(filepath, mode) as f:
        for line in f:
            yield line.split().lower()

for line in open('/nas/minsu/2009_06.txt'):
    tweet = line.strip().lower()

    total_tweet_count += 1

    with open('./related_tweets.txt', 'a') as save_file_1:
        keywords = get_keywords('./related_keywords.txt', 'r')

        if keywords in line:
            text =  line.split('&lt;t&gt;')[1].split('&lt;/t&gt;')[0]

            if 'http://' in text:
                try:
                    url = text.split('http://')[1].split()[0]
                    url = 'http://' + url

                    if url not in URLs:
                        URLs[url] = []
                    URLs[url].append('\t' + text)

                    save_file_3 = open('./URLs_in_related_tweets.txt', 'a')
                    print &gt;&gt; save_file_3, URLs

                except:
                    pass

            if '@' in text:
                mention_count +=1

            if 'RT' in text:
                rt_count += 1

            related_tweet_count += 1

            print &gt;&gt; save_file_1, text

    save_file_2 = open('./info_related_tweets.txt', 'w')

print &gt;&gt; save_file_2, str(total_tweet_count) + '\t' + srt(related_tweet_count) + '\t' + str(mention_count) + '\t' + str(rt_count)

save_file_1.close()
save_file_2.close()
save_file_3.close()
</code></pre>

<p>Following is the sample keywords</p>

<pre><code>Depression
Placebo
X-rays
X-ray
HIV
Blood preasure
Flu
Fever
Oral Health
Antibiotics
Diabetes
Mellitus
Genetic disorders
</code></pre>

<p>I think my code has many problem, but the first error is as follws:</p>

<p>Traceback (most recent call last): File "health_related_tweets.py", line 23, in  if keywords in line: TypeError: 'in ' requires string as left operand, not generator</p>

<p>Please help me out!</p>
