title: Merge two csv files based on key and secondary key
body: <p>I would like to merge two csv files as follows:</p>
  
  <p><strong>csv1:</strong></p>
  
  <pre><code>formula,solver,runtime,conflicts
  CBS_k3_n100_m403_b30_13.cnf,SWDiA5BY,0.001842,318
  CBS_k3_n100_m403_b30_13.cnf,glucose,0.001842,318
  </code></pre>
  
  <p><strong>csv2:</strong></p>
  
  <pre><code>formula,entropy,num sols
  CBS_k3_n100_m403_b30_13.cnf,0.202,707286
  </code></pre>
  
  <p><strong>desired output:</strong></p>
  
  <pre><code>formula,solver,runtime,conflicts,entropy,solutions
  CBS_k3_n100_m403_b30_13.cnf,SWDiA5BY,0.001842,318,0.202,707286
  CBS_k3_n100_m403_b30_13.cnf,glucose,0.001842,318,0.202,707286
  </code></pre>
  
  <p>So I did an intersection between the keys of the two dictionaries (csv's), and used list comprehension</p>
  
  <pre><code>keysA = set(dict1.keys())
  keysB = set(dict2.keys())
  keys = keysA &amp; keysB
  ...
  [[key] + dict1.get(key, []) + dict2.get(key, []) for key in keys]
  </code></pre>
  
  <p>but there are some 'duplicate' rows (which I need) where the field <strong>formula</strong> is the same but the field <strong>solver</strong> isn't, and my output is:</p>
  
  <pre><code>formula,solver,runtime,conflicts,entropy,solutions
  CBS_k3_n100_m403_b30_13.cnf,SWDiA5BY,0.001842,318,0.202,707286
  </code></pre>
  
  <p>How can I keep those rows using list comprehension? or in any other way</p>
  
  <p>appreciate your help</p>
  
  <p>EDIT - added an example</p>