title: How to reduce the number of for-loops for shortening running time in Python programming?
body: <p>I am working on Python programming. 
  The problem is that my code is too slow to get the data in few days.     </p>
  
  <p>My code is as below. And dic dictionary data is like this; dic[0] = ['happy', 100, [1234, 1245, 1515, 1785, ... up to 100]] That is, dic[0][1] represents the length of the dic[0][2]. What I want to do is to calculate DICE Coefficient (word similarity) (dic[i][0] represents a word (in the example above, 'happy'), dic[i][1] represent the length of dic[i][2] (just len(dic[i][2])), dic[i][2] represents the list of line numbers where that word (dic[i][0]) appears. Here line means just the line number in corpus) </p>
  
  <p>DICE Coefficient is calculated in this way : number of appearance of two words (word1, word2) together in a sentence / (number of total appearance of word1 + number of total appearance of word2). </p>
  
  <p>The total data is (so) big. My program has worked for 2 days.. but no result yet.. I have to use the result as soon as possible because this work's deadline is next week.. </p>
  
  <p>Is there any alternative (much better) algorithm that I can implement right away? 
  Thanks. </p>
  
  <pre><code>for j in range(len(dic)):
              for k in range(len(dic)):
  
                  score_temp = 0
  
                  for r in range(len(dic[j][2])):
                      if(dic[j][2][r] in dic[k][2]):
                          score_temp += 1
                  score_final = float(score_temp) / (dic[j][1] + dic[k][1])
                  dice_cursor.execute('insert into dices values(?,?,?)', (dic[j][0], dic[k][0], score_final))
  </code></pre>