How do I obtain values(lines) from file2 using only indices in file1?
<p>I have one file1 with only indices, and second file2 contains the values of these indices of file1. How do I obtain these values from file2 using the indices in file1, and output its value to a third file.For simplicity sake, every index in file1 has its associated values in file2. </p>

<p>For example:</p>

<p>file1:</p>

<pre><code>2
3
4
</code></pre>

<p>file2 contents:</p>

<pre><code>0.24  0.43             
0.34  0.28              
7.50  0.67               
0.23  0.78               
0.45  0.49              
</code></pre>

<p>Expected result</p>

<pre><code>7.50 0.67
0.23 0.78
0.45 0.49
</code></pre>

<p>file1 #contains only indices
file2 #every index in file1 contains values with associated indices</p>

<pre><code>fname = file1.readlines()
fname2 = file2.readlines()
outfile = open('Values.txt','w')

for index in fname:
  for line in fname2:
    if line == index:
      outfile.writelines(line)

print "all indices' values have been written to a file success
</code></pre>
