efficient way of string search in a file
<p>I had 2 files 'example' and 'inp' as follows:</p>

<p>contents of file example:                   </p>

<pre><code>hi      wert    123

jui     fgrt    345

blabla  dfr     233
</code></pre>

<p>contents of file inp:</p>

<pre><code>jui
hi
</code></pre>

<p>I need to fetch the first column of each line of 'example', and if that string exists in file 'inp', then i want to write that entire line of 'example' to another file out.txt
This is the code that i had written:</p>

<pre><code>f=file('example')
f1=file('inp')

for l in f.readlines():
    s=l.split()
    for p in f1.readlines():
            if s[0] in p:
                    print l &gt;&gt; 'out.txt'
</code></pre>

<p>I am not able to get the expected result. And also, since the file example literally has 200000 entries and i think this sort of program takes too much time. Is there any method by which i can complete my task correctly and fast. Help much appreciated. Thank You</p>
