title: nested dictionary python
body: <p>How do I create a nested dictionary in python
  So, I want the data be in this form..</p>
  
  <pre><code>{Category_id: {Product_id:... productInstance},{prod_id_1: this instance}}
  </code></pre>
  
  <p>Basically if i do something like this
  lets say I want to check whether the </p>
  
  <pre><code>product_id = 5 is in category 1.
  </code></pre>
  
  <p>so if I do</p>
  
  <pre><code>Dict[1].has_key(5)--&gt; be true or false..
  </code></pre>
  
  <p>My bad code is </p>
  
  <pre><code>fin = readFile(db)
  categoryDict = defaultdict(list)
  itemDict ={}
  for line in fin:
      itemInstance = setItemInstances(line)
  
      itemDict[itemInstance._product_id] = itemInstance
      categoryDict[itemInstance._category_id].append(itemDict)
  
  
  
  
  EDIT: example
  dict = {1: { p_id: p_instance_1,
             p_id_2: p_ins_2}
       2:{ p_in_this_cat_id: this isntance}}
  </code></pre>
  
  <p>THanks</p>