Is there an elegant way to create a dictionary of arrays?
<p>I frequently analyse data which has a parent child relationship:</p>

<pre><code>data = [
    {'data': 'somedata', 'id': 1, 'parentId': 0},
    {'data': 'somedata', 'id': 2, 'parentId': 1},
    {'data': 'somedata', 'id': 3, 'parentId': 0},
    {'data': 'somedata', 'id': 4, 'parentId': 3},
    {'data': 'somedata', 'id': 5, 'parentId': 3},
]
</code></pre>

<p>Typically I'll use a loop like this to create a new data structure so I can easily relate parent and child data:</p>

<pre><code>for item in data:
    if item["parentId"] != 0:
        if item["parentId"] in parents:
            parents[item["parentId"]].append(item["id"])
        else:
            parents[item["parentId"]] = []
            parents[item["parentId"]].append(item["id"])
</code></pre>

<p>This produces the following data:</p>

<pre><code>print parents
{1: [2], 3: [4, 5]}
</code></pre>

<p>Is there a more elegant way to create the "parents" data structure?</p>
