faster and more 'pythonic' list of dictionaries
<p>For simplicity, I've provided 2 lists in a list, but I'm actually dealing with a hundred of lists in a list, each containing a sizable amount of dictionaries. I only want to get the value of 'status' key in the 1st dictionary without checking any other dictionaries in that list (since I know they all contain the same value at that key). Then I will perform some sort of clustering within each big dictionary. I need to efficiently concatenate all 'title' values. Is there a way to make my code more elegant and much faster?</p>

<p>I have:</p>

<pre><code>nested = [
    [
        {'id': 287, 'title': 'hungry badger',  'status': 'High'},
        {'id': 437, 'title': 'roadtrip to Kansas','status': 'High'}
    ],
    [
        {'id': 456, 'title': 'happy title here','status': 'Medium'},
        {'id': 342,'title': 'soft big bear','status': 'Medium'}
    ]
]
</code></pre>

<p>I'd like:</p>

<pre><code>result = [
    {
        'High': [
            {'id': 287, 'title': 'hungry badger'},
            {'id': 437, 'title': 'roadtrip to Kansas'}
        ]
    },
    {
        'Medium': [
            {'id': 456, 'title': 'happy title here'},
            {'id': 342, 'title': 'soft big bear'}
        ]
    }
]
</code></pre>

<p>What I tried:</p>

<pre><code>for oneList in nested: 
   result= {}
   for i in oneList:        
       a= list(i.keys()) 
       m= [i[key] for key in a if key not in ['id','title']]
       result[m[0]]=oneList
       for key in a:
            if key not in ['id','title']:
                del i[key]
</code></pre>

<p>You could make a <code>defaultdict</code> for each nested list:</p>

<pre><code>import collections
nested = [
[{'id': 287, 'title': 'hungry badger',  'status': 'High'},
{'id': 437, 'title': 'roadtrip to Kansas','status': 'High'}],     
[{'id': 456, 'title': 'happy title here','status': 'Medium'},
{'id': 342,'title': 'soft big bear','status': 'Medium'}]   ]
result = []
for l in nested:
    r = collections.defaultdict(list)
    for d in l:
        name = d.pop('status')
        r[name].append(d)
    result.append(r)
</code></pre>

<p>This gives the following <code>result</code>:</p>

<pre><code>&gt;&gt;&gt; import pprint
&gt;&gt;&gt; pprint.pprint(result)
[{'High': [{'id': 287, 'title': 'hungry badger'},
           {'id': 437, 'title': 'roadtrip to Kansas'}]},
 {'Medium': [{'id': 456, 'title': 'happy title here'},
             {'id': 342, 'title': 'soft big bear'}]}]
</code></pre>

python dictionary