Код: Выделить всё
Data = [
{
'Name': 'A1',
'Value': 10,
'Type': 'AAA'
},
{
'Name': 'A1',
'Value': 20,
'Type': 'AAA'
},
{
'Name': 'B1',
'Value': 10,
'Type': 'AAA'
},
{
'Name': 'C1',
'Value': 10,
'Type': 'BBB'
},
{
'Name': 'D1',
'Value': 10,
'Type': 'BBB'
}
]
Код: Выделить всё
Data = {
'AAA': [
'A1': [
{
'Name': 'A1',
'Value': 10,
'Type': 'AAA'
},
{
'Name': 'A1',
'Value': 20,
'Type': 'AAA'
},
],
'B1': [
{
'Name': 'B1',
'Value': 10,
'Type': 'AAA'
},
]
],
'BBB': [
'C1': [
{
'Name': 'C1',
'Value': 10,
'Type': 'BBB'
}
],
'D1': [
{
'Name': 'D1',
'Value': 10,
'Type': 'BBB'
},
]
]
}
Я делал что-то вроде этого,
Код: Выделить всё
tTmp_List_1 = []
tTmp_List_2 = []
tTmp_Name_List_1 = []
tTmp_Name_List_2 = []
for tValue in Data:
if (tValue['Type'] == 'AAA'):
tTmp_List_1.append(tValue)
tTmp_Name_List_1.append(tValue['Name'])
if (tValue['Type'] == 'BBB'):
tTmp_List_2.append(tValue)
tTmp_Name_List_2.append(tValue['Name'])
tTmp_Name_List_1 = list(set(tTmp_Name_List_1))
tTmp_Name_List_2 = list(set(tTmp_Name_List_2))
Код: Выделить всё
tTmp_Dict = {}
for tTmp_Name in tTmp_Name_List_1 :
tTmp = []
if (Data['Name'] == tTmp_Name):
tTmp.append(Data)
tTmp_Dict.append(tTmp)
Любая помощь очень ценится.Спасибо
Подробнее здесь: https://stackoverflow.com/questions/792 ... -in-python
Мобильная версия