title: Python Joining csv files where key is first column value
body: <p>I try to join two csv files where key is value of first column.
  There's no header.<br>
  Files have different number of lines and rows.<br>
  Order of file a must be preserved.</p>
  
  <p>file a:</p>
  
  <pre><code>john,red,34
  andrew,green,18
  tonny,black,50
  jack,yellow,27
  phill,orange,45
  kurt,blue,29
  mike,pink,61
  </code></pre>
  
  <p>file b:</p>
  
  <pre><code>tonny,driver,new york
  phill,scientist,boston
  </code></pre>
  
  <p>desired result:</p>
  
  <pre><code>john,red,34
  andrew,green,18
  tonny,black,50,driver,new york
  jack,yellow,27
  phill,orange,45,scientist,boston
  kurt,blue,29
  mike,pink,61
  </code></pre>
  
  <p>I examined all related threads and I am sure that some of you are gonna mark this question duplicate but I simply have not found solution yet.</p>
  
  <p>I grabbed dictionary based solution but this approach does not handle preserve line order from file 'a' condition.</p>
  
  <pre><code>import csv
  from collections import defaultdict
  
  with open('a.csv') as f:
      r = csv.reader(f, delimiter=',')
      dict1 = {}
      for row in r:
          dict1.update({row[0]: row[1:]})
  
  with open('b.csv') as f:
      r = csv.reader(f, delimiter=',')
      dict2 = {}
      for row in r:
          dict2.update({row[0]: row[1:]})
  
  result = defaultdict(list)
  
  for d in (dict1, dict2):
      for key, value in d.iteritems():
          result[key].append(value)
  </code></pre>
  
  <p>I also would like to avoid putting these csv files to the database like sqlite or using pandas module.</p>
  
  <p>Thanks in advance</p>