title: List of lists to store in MongoDB
body: <p>I have below a list which I stored in a nested <code>defaultdict</code>:</p>
  
  <pre><code>from collections import defaultdict
  
  if __name__ == "__main__":
  
  r = [["Test", "A", "B01", 828288,  1,    7, 'C', 5],
      ["Test", "A", "B01", 828288,  1,    7, 'T', 6],
      ["Test", "A", "B01", 171878,  3,    8, 'C', 5],
      ["Test", "A", "B01", 171878,  3,    8, 'T', 6],
      ["Test", "A", "B01", 871963,  3,    9, 'A', 5],
      ["Test", "A", "B01", 871963,  3,    9, 'G', 6],
      ["Test", "A", "B01", 1932523, 1,   10, 'T', 4],
      ["Test", "A", "B01", 1932523, 1,   10, 'A', 5],
      ["Test", "A", "B01", 1932523, 1,   10, 'X', 6],
      ["Test", "A", "B01", 667214,  1,   14, 'T', 4],
      ["Test", "A", "B01", 667214,  1,   14, 'G', 5],
      ["Test", "A", "B01", 667214,  1,   14, 'G', 6]]
  
  s = defaultdict(lambda:
          defaultdict(lambda:
                  defaultdict(lambda:
                      defaultdict(lambda:
                              defaultdict(lambda:
                                  defaultdict(lambda:
                                          defaultdict(defaultdict)))))))
  
  for i in r:
      s[i[0]][i[1]][i[2]][i[3]][i[4]][i[5]][i[6]] = i[7]
  </code></pre>
  
  <p>But, I am not sure how to convert the above nested defaultdict to a Dict/JSON (see below) so it can be stored to MongoDB.</p>
  
  <pre><code>{
  type: "Test", 
  name: "A", 
  sub_name: "B01", 
  pos: 828288,  
  s_type: 1,    
  x_type: 7, 
  chr = {
        'C': 5
        'T': 6
        }
  }
  </code></pre>
  
  <p>Is there maybe a way to avoid to create a nested defaultdict and store directly each element to MongoDB and apply an update?</p>
  
  <p><strong>Update</strong>: For the first list it should be <code>'chr': { 'i[6]': i[7]}</code> which should give <code>'chr': { 'C': 5}</code>. 
  For the second list which is only different on last two elements compare to the first list. 
  I wanted to add <code>'T', 6</code> to the previous <code>chr</code> to get <code>'chr': { 'C': 5, 'T', 6}</code>.
  I created the nested <code>defaultdict</code> in order to combine the same elements and the last two elements which are different I wanted to store them in chr dict.</p>