I have two large file data sets:
File1:
Gen1 1 1 10
Gen2 1 2 20
Gen3 2 30 40
File2:
A 1 4
B 1 15
C 2 2
Expected output:
Out:
Gen1 1 1 10 A 1 4
Gen2 1 2 20 B 1 15
Now I have code which basically is just trying to find instances where file 2 is in file 1 if the file2[1] matches file1[1] and falls between the range in file 1.
My code that does this is below:
for i in file1:
temp = i.split()
for a in file2:
temp2 = a.split()
if temp[1] == temp2[1] and temp2[2] >= temp[2] and temp2[2] <= temp[3]
print(i + " " + a + "\n")
else:
continue
The code works, but I feel that it takes a lot longer than it should. Is there a simpler way or method to do this? I feel that there is some sort of clever use of map or hashes that I'm not doing.
Thank you!