Python - Searching .csv file with rows from a different .csv file
<p>All -</p>

<p>I am attempting to read a single row from a csv file and then have it search another csv file.</p>

<p>I have a masterlist.csv that has a single column called empID.  It contains thousands of rows of 9 digit numbers. As well I have ids.csv that also contains a single column called number.  It contains hundreds of rows.  I am attempting to pull a row from the ids.csv do a search on the masterlist.csv and print out whether it has been found. Then it needs to move to the next row in ids.csv until each row in ids.csv has been searched within the masterlist.csv.
I thought it would be as simple as this, however it is not throwing any errors nor returning any results.</p>

<p>Using Python 2.7.12
    import csv</p>

<pre><code>masterReader = csv.reader(open("masterlist.csv", "rt"), delimiter=",")
idsReader = csv.reader(open("ids.csv", "rt"), delimiter=",")


for number in idsReader:
    for empID in masterReader:
        if number == empID:
            print (" Found in MasterFile")
        else:
            print ("Is Not Found in MasterFile")
</code></pre>

<p>Edit: Adding snippet of data used for testing.</p>

<p><a href="http://i.stack.imgur.com/vJroB.png" rel="nofollow"><img src="http://i.stack.imgur.com/vJroB.png" alt="enter image description here"></a></p>

<p><a href="http://i.stack.imgur.com/nYhe4.png" rel="nofollow"><img src="http://i.stack.imgur.com/nYhe4.png" alt="enter image description here"></a></p>

<p><strong>Content of master.csv</strong></p>

<pre><code>EmpId
111111111
222222222
333333333
444444444
</code></pre>

<p><strong>Content of ids.csv:</strong></p>

<pre><code>Number
111111111
999999999
444444444
555555555
222222222
</code></pre>

<p><strong>Code:</strong></p>

<pre><code>import csv

f1 = file('master.csv', 'r')
f2 = file('ids.csv', 'r')

c1 = csv.reader(f1)
c2 = csv.reader(f2)

idlist = list(c2)
masterlist = list(c1)

for id in idlist[1:]:
    found = False
    #Need to ignore heading thats why masterlist[1:]
    for master in masterlist[1:]:
        if id == master:
            found = True
    if found:
        print "Found in master file"
    else:
        print "Not found in master file"

f1.close()
f2.close()
</code></pre>

<p><strong>Output:</strong></p>

<pre><code>C:\Users\dinesh_pundkar\Desktop&gt;python c.py
Found in master file
Not found in master file
Found in master file
Not found in master file
Found in master file

C:\Users\dinesh_pundkar\Desktop&gt;
</code></pre>

<p><strong><em>More shorter version of code without CSV module</em></strong></p>

<pre><code>with open('master.csv','r') as master:
    with open('ids.csv','r') as id:
        id_list = id.readlines()[1:]
        master_list = master.readlines()[1:]
        for id in id_list:
            if id in master_list:
                print "Found in master file"
            else:
                print "Not found in master file"
</code></pre>

python csv