title: Appending input from csv file to a dictionary including duplicate values for a unique key
body: <p>First, I want to say that I am new to programming. That said, using Python 2.76, I'm trying to take a text file, read it in with csv, and then create a dictionary with a key equal to the first column in the file. Here is an example of the type of file I want to use (sorry for the bad formatting, there are three columns, each with a given value of either visitid, date, or time):</p>
  
  <blockquote>
    <p>visitid    cdate   ctime</p>
    
    <p>OMHioJh8XEeq7152       6/15/2007   06:00</p>
    
    <p>OMHioJh8XEeq7152   6/14/2007   07:10</p>
    
    <p>OMHioJh8XEeq7152   6/11/2007   14:21</p>
    
    <p>t2v0TjgroLTI6118   4/28/2006   14:18</p>
    
    <p>t2v0TjgroLTI6118   5/1/2006    04:00       </p>
  </blockquote>
  
  <p>Specifically, given this kind of list, I want to make a key in the dictionary equal to the value of the first column, and for the value have the remaining columns as a list.  Finally, I want to append the value with another list if there are duplicates of the value in column 1 to form a list of lists, so to speak.  This is what I have so far, after doing some research on here and elsewhere:</p>
  
  <pre><code>def test_results(filename):
  import csv
  with open(filename,"rU") as f:
      reader = csv.reader(f,delimiter="\t")
      result = {}
      for row in reader:
          key = row[0]
          if key in result:
              result[row[0]].append(row[1])
          else:
              result[row[0]] = key
          result[key]=row[1:]
      print result
  </code></pre>
  
  <p>This works, but it does not append the values to make a list of lists, and only adds to the dictionary the last row for any unique visitID.</p>
  
  <p>Thanks!</p>