How can I create this list of dicts
<p>I have a list of dicts</p>

<pre><code>[{'name_field': u'casino_logo', 'contentid_id': 15L, 'value': u'assets/images/crown.png', 'title': u'Royal casino casino4'}, {'name_field': u'casino_logo', 'contentid_id': 16L, 'value': u'assets/images/crown.png', 'title': u'Royal casino casino1'}, {'name_field': u'casino_logo', 'contentid_id': 17L, 'value': u'assets/images/crown.png', 'title': u'Royal casino casino3'}, {'name_field': u'casino_logo', 'contentid_id': 18L, 'value': u'assets/images/crown.png', 'title': u'Royal casino casino2'}, {'name_field': u'raiting_casino', 'contentid_id': 15L, 'value': u'9.9', 'title': u'Royal casino casino4'}, {'name_field': u'raiting_casino', 'contentid_id': 16L, 'value': u'9', 'title': u'Royal casino casino1'}, {'name_field': u'raiting_casino', 'contentid_id': 17L, 'value': u'8.2', 'title': u'Royal casino casino3'}, {'name_field': u'raiting_casino', 'contentid_id': 18L, 'value': u'9.3', 'title': u'Royal casino casino2'}, {'name_field': u'bonus_code', 'contentid_id': 15L, 'value': u'AX777', 'title': u'Royal casino casino4'}, {'name_field': u'bonus_code', 'contentid_id': 16L, 'value': u'AX7772', 'title': u'Royal casino casino1'}, {'name_field': u'bonus_code', 'contentid_id': 17L, 'value': u'AX777', 'title': u'Royal casino casino3'}, {'name_field': u'bonus_code', 'contentid_id': 18L, 'value': u'AX7772', 'title': u'Royal casino casino2'}, {'name_field': u'bonus_summa', 'contentid_id': 15L, 'value': u'200', 'title': u'Royal casino casino4'}, {'name_field': u'bonus_summa', 'contentid_id': 16L, 'value': u'200', 'title': u'Royal casino casino1'}, {'name_field': u'bonus_summa', 'contentid_id': 17L, 'value': u'200', 'title': u'Royal casino casino3'}, {'name_field': u'bonus_summa', 'contentid_id': 18L, 'value': u'200', 'title': u'Royal casino casino2'}, {'name_field': u'bonus_min_depozit', 'contentid_id': 15L, 'value': u'1000000', 'title': u'Royal casino casino4'}, {'name_field': u'bonus_min_depozit', 'contentid_id': 16L, 'value': u'1000000', 'title': u'Royal casino casino1'}, {'name_field': u'bonus_min_depozit', 'contentid_id': 17L, 'value': u'1000000', 'title': u'Royal casino casino3'}, {'name_field': u'bonus_min_depozit', 'contentid_id': 18L, 'value': u'1000000', 'title': u'Royal casino casino2'}, '...(remaining elements truncated)...']
</code></pre>

<p>How can I get the structure</p>

<pre><code>{casinos:[{'id':16,'title':Royal casino casino3,'fields':[{'name_feild':'bonus_min_depozit','value':'10',...}],...}]}
</code></pre>

<p>I tried:</p>

<pre><code>for item in casinos:  
    info_casino[item['contentid_id']].append({'name_field':item['name_field'],'value':item['value']}) 
    casino[item['contentid_id']] = {'fields':info_casino[item['contentid_id']],'title':item['title']}
</code></pre>

<p>but it didn't work. </p>

<p>You can use a <em>"dictionary comprehension"</em> to achieve this as:</p>

<pre><code>my_dict = {item['name_field']: item for item in my_list}
</code></pre>

<p>where <code>my_list</code> is the list of <code>dict</code> as is mentioned in the question.</p>

<p>In case you want to remove the <code>'name_field'</code> value of the resulting dict, you can create the new <code>dict</code> as:</p>

<pre><code>my_dict = {}
for item in my_list:
    my_dict[item['name_field']] = item
    del item['name_field']
</code></pre>

python list dictionary data-structures