title: How can I create a dynamic dictionaries in Python using a CSV file
body: <p>The problem is simple, I have a CSV file with four columns I wanted to value of the first column and make that into a dictionary in my python script. I don't want to add values to the dictionary dates of tasks completed.</p>
  
  <p>The CSV data for this is found in a file called VC.csv, for example this:</p>
  
  <pre class="lang-none prettyprint-override"><code>24M Technologies,Series A,8/19/10
  24M Technologies,Grant,8/16/10
  2B Energy,Private Equity,3/18/14
  2B Energy,Series B,3/18/14
  2B Energy,Unattributed VC,5/1/08
  3GSolar Photovoltaics,Series A,12/17/12
  3sun Group,Growth Equity,3/3/14
  3Tier Group,Series C,11/17/08
  </code></pre>
  
  <p>The end result I would like to have are dictionaries that are like this when I print them.</p>
  
  <p>For example</p>
  
  <pre><code>&gt;&gt;&gt; print 3TierGroup
  &gt;&gt;&gt;
  &gt;&gt;&gt;{'company': '2B Energy', 'Private Equity': '3/18/14', 'Series B': '3/18/14', 'Unattributed VC': '05/01/08'}
  </code></pre>
  
  <p>Where my problem is is trying to loop trough and add more to a already defined dictionary. Instead of appending I'm guessing I'm recreating and overwriting the loop every pass.  What I get as a result is <code>{'company': '2B Energy', 'Private Equity': '3/18/14'}</code>  I need the last line of my code to test to see if the dictionary is already present; if so it would append the additionally round dates to it. </p>
  
  <p>Here is my code...</p>
  
  <pre><code>import csv
  
  companyList =[]
  transactionDates=[]
  dictNames=[]
  
  def fileNameCleaner(namer):
      namer = namer.replace(' ', '')
      namer = namer.replace(',','')
      namer = namer.replace('-','')
      namer = namer.replace('.','')
      namer = namer.replace('_','')
      namer = namer.replace('@','')
      namer = namer.replace('&amp;','')
      return namer
  
  with open('VC.csv', 'rb') as rawData:
      timelineData = csv.reader(rawData, delimiter=',', quotechar='"')      # Open CSV file and snag data
      for line in timelineData:  # Run through each row in csv
          companyList.append(fileNameCleaner(line[0])) # Create list and remove some special charcters
      companyList = list(set(companyList))    # Remove duplicates and Sort
  
  for companyListRow in companyList:
      with open('VC.csv', 'rb') as rawDataTwo:
          timelineDataTwo = csv.reader(rawDataTwo, delimiter=',', quotechar='"')
          for TList in timelineDataTwo:
              company = TList[0]
              finRound = TList[1]
              tranDate = TList[2]
              if companyListRow == fileNameCleaner(TList[0]):
                  companyListRow = {'company':TList[0], finRound:tranDate }
                  print companyListRow
  </code></pre>