title: python KeyError on parsing a dictionary
body: <p>How can i join these two text documents?<br /></p>
  
  <p><strong>document 1:</strong></p>
  
  <pre><code>1000001 10:0.471669 250:0.127552 30:0.218773 64:0.249413
  1000002 130:0.0839656 107:0.185613 30:0.446355 110:0.38011
  1000003 1:0.0835855 1117:0.0647112 302:0.0851354 46:0.0601825 48:0.098907 516:0.167713
  </code></pre>
  
  <p><strong>document 2:</strong></p>
  
  <pre><code>1000001 161:0.115664 207:0.136537 294:0.0974809 301:0.199868
  1000002
  1000003 555:0.0585849 91:0.0164101
  </code></pre>
  
  <p><strong>result:</strong></p>
  
  <pre><code>1000001 10:0.471669 250:0.127552 30:0.218773 64:0.249413 161:0.115664 207:0.136537 294:0.0974809 301:0.199868
  1000002 130:0.0839656 107:0.185613 30:0.446355 110:0.38011
  1000003 1:0.0835855 1117:0.0647112 302:0.0851354 46:0.0601825 48:0.098907 516:0.167713 555:0.0585849 91:0.0164101
  </code></pre>
  
  <p><strong>explanation:</strong><br />
  <strong>document 1</strong> and <strong>document 2</strong> both have the same structure and they have the same number of lines.<br /> Each line starts with a number (the same number in both documents), and then we have several items in each line which are made up of a number+colon+a decimal number: <br /><em>example</em> <strong>10:0.471669</strong><br />
  these item combinations are unique, what I want to do is to merge them together: take the items from the second document for each line and put it in the corresponding line of the first document.<br />
  <em>note:</em><br />
  the initial number at the beginning and the items from one another are separated by a single space.</p>
  
  <h2>update</h2>
  
  <p>here is my try:<br /></p>
  
  <pre><code>dat1 = {}
  with open('doc1') as f:
      for line in f.readlines():
          dat1[line.split(' ')[0]] = line.strip().split(' ')[1:]
  
  dat2 = {}
  with open('doc2') as f:
      for line in f.readlines():
          key = line.split(' ')[0]
          dat2[key] = line.split(' ')[1:]
  
  for key in dat1.keys():
      print("%s %s %s" % (key, str.join(' ', dat1[key]), str.join(' ', dat2[key])))
  </code></pre>
  
  <p>i get a traceback of KeyError, on the lines of the second document when the line doens't have anything to be added to the first document. It is the case in the second line of the second document in the above example. <br/> How can I escape this exception? escape the lines which have only the key and nothing else to add?</p>