title: How to parallelize two iterators?
body: <p>This is a follow up from my question <a href="https://stackoverflow.com/questions/19541523/paralel-for-loop-map-works-pool-map-gives-typeerror/">Paralel for loop, map() works, pool.map() gives TypeError</a>. I want to do <code>multiprocessing.Pool.map(compare_clusters, clusters_1, clusters_2)</code>, where compare_clusters is a function, clusters_1 is a list of objects and clusters_2 is also a list of objects. The <a href="https://stackoverflow.com/a/19541658/651779">answer</a> to that question made it clear that unlike <code>map</code>, <code>multiprocessing.Pool.map</code>  can only take one iterator, and in this case <code>clusters_2</code> would have to be chunk size.</p>
  
  <p>So my question is, how can I parallelize a loop with two iterators?</p>
  
  <p>The code</p>
  
  <pre><code>spectra_names, condensed_distance_matrix, index_0 = [], [], 0 
  for index_1, index_2 in itertools.combinations(range(len(clusters)), 2):
      if index_0 == index_1:
          index_0 += 1
          spectra_names.append(clusters[index_1].get_names()[0])
      try:
          distance = 1/float(compare_clusters(clusters[index_1], clusters[index_2],maxiter=50))
      except:
          distance = 10
      condensed_distance_matrix.append(distance)
  </code></pre>
  
  <p>How I tried to parallelize it</p>
  
  <pre><code>from multiprocessing import Pool
  condensed_distance_matrix, spectra_names, index_0, clusters_1, clusters_2 = [], [], 0, [], []
  for index_1, index_2 in itertools.combinations(range(len(clusters)), 2):
      if index_0 == index_1:
          index_0 += 1
          spectra_names.append(clusters[index_1].get_names()[0])
      clusters_1.append(clusters[index_1])
      clusters_2.append(clusters[index_2])
  pool = Pool()
  condensed_distance_matrix_values = pool.map(compare_clusters, clusters_1, clusters_2)
  
  for value in condensed_distance_matrix_values :
      try:
          distance = 1/float(value)
      except:
          distance = 10
      condensed_distance_matrix.append(distance)
  </code></pre>