a = [{ 'id': '123', 'name': 'A', 'type': 'software' },
{ 'id': '102', 'name': 'Adfds', 'type': 'software' },
{ 'id': '222', 'name': 'sxds', 'type': 'software' }]
代码如下
{{key:val} for each in a for key,val in each.items()}
预料之外
{ '123': { 'name': 'A', 'type': 'software' },
'102': { 'name': 'Adfds', 'type': 'software' },
'222': { 'name': 'sxds', 'type': 'software' } }
您可以尝试以下方法:
输出:
您可以这样做:
字典不能有重复的键
在您的示例中,您正在向同一个键添加不同的值。以下是您必须做的:
相关问题 更多 >
编程相关推荐