我有一个看起来像这样的字典列表
list = [
{Name: Fred, Points: 1, Date: 1-20-2020},
{Name: Fred, Points: 3, Date: 1-15-2020},
{Name: Fred, Points: 5, Date: 1-13-2020},
]
我怎样才能按名称将它们组合起来呢?
list = [{
Name: Fred, Scores: [{
Points: 1, Date: 1-20-2020,
Points: 3, Date: 1-15-2020,
Points: 5, Date: 1-13-2020
]
]
我试图创建一个名称列表,然后将其余值映射回名称,但这没有按预期工作。
names = []
for name in list:
names.append(
{
'Name': name['Name']
})
for name in list:
for name in names:
if name['Name'] == name['Name']:
name['Scores'] = [
{
'Date': name['Date'],
'FPTS': name['Points']
}]
白板的微信
相关分类