How do I match 0,2,3,4 elements of one array to 0,2,3,4 elements of another array and print the 5th element from both the arrays in python?
<p>I am trying to match the 0,2,3,4 elements of an array storing the columns of one tab delimited file to 0,2,3,4 elements of another array storing the columns of another tab delimited file and print out the element 5 (column 6) from both the input files in python.</p>

<p>Here is the code that I worked on but I guess that the code matches line by line between two files. However, I wanted to match the line of  file1 to any line in file 2</p>

<pre><code>#!/usr/bin/python
import sys
import itertools
import csv, pprint
from array import *
#print len(sys.argv)
if len(sys.argv) != 4:
print 'Usage: python scores.py &lt;infile1&gt; &lt;infile2&gt; &lt;outfile&gt;'
sys.exit(1)

f1=open("/home/user/ab/ab/ab/file1.txt", "r")
f2 = open ("/home/user/ab/ab/ab/file2.txt", "r")
f3 = open ("out.txt", "w")

lines1 = f1.readlines()
lines2 = f2.readlines()

for f1line, f2line in zip(lines1, lines2): ## for loop to read lines line by line simultaneously from two files
    #for f1line, f2line in itertools.izip(lines1,lines2):
    row1 = f1line.split('\t') #split on tab
    row2 = f2line.split('\t') # split on tab

    if ((row1[0:1] + row1[2:5]) == (row2[0:1] + row2[2:5])): # columns 0,2,3,4 matching between two infiles 
        writer = csv.writer(f3, delimiter = '\t')
        writer.writerow((row1[0:1] + row1[2:5]) + row1[5:6] + (row2[0:1] + row2[2:5]) + row2[5:6])
</code></pre>
