<pre><code>dictt = list(map(lambda x: {'manufacturer_id':x['manufacturer_id'],'manufacturer_name':x['manufacturer_name'] }, laptop_list))
no_duplicate_dict = [dict(t) for t in {tuple(d.items()) for d in dictt}]
sub_dict = list(map(lambda x: [x['manufacturer_id'], {'model_number':x['model_number'], 'model_name':x['model_name']}], laptop_list))
grouped_dict = [ [ID]+[[x[1] for x in sub_dict if x[0] == ID]] for ID in set([id[0] for id in sub_dict]) ]
list(map(lambda x: x.update( {'models' : [sub_dict[1][0-len(sub_dict[1])] for sub_dict in grouped_dict if x['manufacturer_id'] == sub_dict[0]] }), no_duplicate_dict))
print(no_duplicate_dict)
>>> [{'manufacturer_id': 2, 'manufacturer_name': 'HP', 'models': [{'model_number': 101010, 'model_name': 'pavillion'}]}, {'manufacturer_id': 1, 'manufacturer_name': 'Lenovo', 'models': [{'model_number': 0, 'model_name': 'Legion'}]}]
</code></pre>
<p>我把一个用<code>manufacturer_id and manufacturer_name</code>和另一个用<code>model_number and model_name</code>分开列出</p>
<p>然后,我添加了来自<code>model_number and model_name</code>的子列表,其中的字典位于``制造商id和制造商名称<code>that matched up using</code>制造商id``列表中,作为匹配它们的键</p>
<p>这一行<code>no_duplicate_dict = [dict(t) for t in {tuple(d.items()) for d in dictt}]</code>刚刚删除了重复的字典</p>