title: How to use threads in python
body: <p>I want to use it for reading values in 17770 files and to add all of them at the end to one dictionary object. I have a machine with 8 cores.</p>
  
  <p>This is the code</p>
  
  <pre><code>def run_item_preprocess ():
      scores = {};
      for i in range(1,17771):
          filename1 = "x_" + str(i) + ".txt";
          lines1 = open(filename1).readlines();
          Item1 = {};
          for line in lines1:
              tokens = line.split(',');
              Item1[int(tokens[1])] = int(tokens[2]);
          for j in range(1,17771):
              if j == i:
                  continue;
              filename2 = "x_" + str(i) + ".txt";
              lines2 = open(filename2).readlines();
              Item2 = {};
              for line in lines2:
                  tokens = line.split(',');
                  u = int(tokens[1]);
                  r = int(tokens[2]);
                  if u in Item1:
                      Item2[u] = r;
              if i not in scores:
                  scores[i] = {};
              scores[i]= (s(Item1,Item2),j);
  </code></pre>