title: How to dynamically update a defaultdict with placeholders
body: <p>I'm having issues trying to dynamically update a dictionary as I add values to keys. </p>
  
  <p>The code below essentially function to loop through subdirectories, then loops through files in each subdirectory. Each file is then simply parsed and data is added to a defaultdict dictionary. The data consists of two fields: chrLocation (keys) and editRatio (values). What I am trying to accomplish here is to accommodate for those keys that were not initially added from the first file. Note that the keys are unique in each file but there can be duplicates among other files. Likewise, there can be keys that appear in, say file7 that was not in the first 6 files. I'd like to show this in my dictionary by have 6 placeholders (zeros) before the first key entry. </p>
  
  <pre><code>dataDict = defaultdict(list)
  for root, dirs, filenames in os.walk(rootdir + "/out/"):
      for d in dirs:
          print "Processing: ", d
          colNames.append(d + "_" + sampOriginDict[d])
              for editingFile in os.listdir(rootdir + "/out/" + d):
                  eFile = open(rootdir + "/out/" + d + "/" + editingFile, 'r')
                  for line in eFile:
                      # only care about 3 fields (chromosome, location and editratio)
                      chromosome, location, x1, x2, x3, x4, editRatio, x5, x6, x7 = line.split("\t")
                      chrLocation = chromosome + "_" + location
                      dataDict[chrLocation].append(editRatio)
  </code></pre>
  
  <p>Brief output is shown below for looping through 2 files: </p>
  
  <pre><code>chr17_37916827 ['0.15']
  chr16_29681751 ['0.1']
  chr6_150045787 ['0.33']
  chr10_75538108 ['0.43', '0.71']
  chr15_64447436 ['0.5', '0.5']
  chr16_15794023 ['0.21', '0.18']
  </code></pre>
  
  <p>As of now the code does not accommodate for placeholders. So, by looking at the output, I'm not sure if that '0.15' came from the first file or the second. </p>
  
  <p>Any help would be much appreciated. Thank you</p>
  
  <p>EDIT: I've added a conditional to check if a key already exists and this was the resulting output: </p>
  
  <pre><code>chr17_37916827 ['File2']
  chr16_29681751 ['File1']
  chr6_150045787 ['File2']
  chr10_75538108 ['File1', 'exists']
  chr15_64447436 ['File1', 'exists']
  chr16_15794023 ['File1', 'exists']
  </code></pre>
  
  <p>Code: </p>
  
  <pre><code>if chrLocation in dataDict.keys(): 
      dataDict[chrLocation].append("exists")
  else:
      dataDict[chrLocation].append(d)
  </code></pre>
  
  <p>I'd like to achieve the output: </p>
  
  <pre><code>chr17_37916827 ['0', 'File2']
  chr16_29681751 ['File1', '0']
  chr6_150045787 ['0', 'File2']
  chr10_75538108 ['File1', 'exists']
  chr15_64447436 ['File1', 'exists']
  chr16_15794023 ['File1', 'exists']
  </code></pre>