title: iteration over 3 large lists to compare and assign value python
body: <p>I have a piece of code where I need to go through many lists to read and assign values</p>
  
  <p>The code does the following:
  First, for each element in the <strong>entities</strong> (1st list 1300), the code will read its text file that contains many <strong>lines</strong> (2nd list 5000) each line contains two values. After that, the code will check if the first value in each line exists in the <strong>features</strong> list (3rdlist 17000), if yes it will write the second value in the line into the matrix. 
  The code is working but it is inefficient and extremely slow.(more than 12 hours)   </p>
  
  <pre><code> #first list
  for i in range(len(entities_list)-1):
      fin = open('/home/rana/'+entities_list[i]+'.txt','r')
              #Second List
              for line in fin.readlines():
                   #Third List
                  for j in range(len(features_list)-1):
                  if features_list[j]==line.split()[0]:
                      co_occurrence_matrix[i,j]=float(line.split()[1])
  </code></pre>
  
  <p>I will appreciate if someone gives me an Idea how to solve this issue</p>