title: Appending associative arrays in Python
body: <p>I've been all over looking for a solution to this recently, and so far to no avail. I'm coming from php to python, and running into an associative array difference I'm not sure now to overcome.</p>
  
  <p>Take this line:</p>
  
  <pre><code>data[user]={i:{'item':row[0],'time':row[1]}}
  </code></pre>
  
  <p>This overwrites each of my <code>data[user]</code> entries, obviously, as it's not appending, it's just replacing the data each time.</p>
  
  <p>In php if I wanted to append a new bit of data in a for loop, I could do</p>
  
  <pre><code>data[user][i][]=array('item'=&gt;'x','time'=&gt;'y'); // crude example
  </code></pre>
  
  <p>In python, I can't do:</p>
  
  <pre><code>data[user][]={i:{'item':row[0],'time':row[1]}}
  </code></pre>
  
  <p>It barfs on my <code>[]</code></p>
  
  <p>I also can't do:</p>
  
  <pre><code>data[user][i]={'item':row[0],'time':row[1]}
  </code></pre>
  
  <p>where I is my iterator through the loop... and I think it's because the <code>data[user]</code> hasn't been defined, yet, as of the operating? I've created the <code>data={}</code>, but I don't have it populated with the users as keys, yet.</p>
  
  <p>In python, do I have to have a key defined before I can define it including a sub-key?</p>
  
  <p>I've tried a bunch of <code>.append()</code> options, and other weird tricks, but I want to know the <em>correct</em> method of doing this.</p>
  
  <p>I <em>can</em> do:</p>
  
  <pre><code>data[user,i]={'item':row[0],'time':row[1]}
  </code></pre>
  
  <p>but this isn't what I want.</p>
  
  <p>What's my proper method here, python friends?</p>