尝试对另一本词典中的词典列表进行排序

时间:2019-03-29 15:54:40

标签: python-3.x pycharm

我需要对字典列表进行排序以比较数据。

  • 我尝试了list的sort()函数
  • 我尝试了排序(My_dict [“ IndividualDUC”] [列表硬件],key = lambda x:x [1])

排序前字典

  My_dict = {'IndividualDUC':
     {'List hardware':
      [
        {'AMDEVBOS': {'Group': 'Default','Version': 'Not installed'}}, 
        {'ATM0-IT-QAV1': {'Group': 'IT', 'Version': 'Not installed'}}, 
        {'ATM0-PEO-QAV2': {'Group': 'PECO', 'Version': '10.0.40219'}}, 
        {'ATM0-PEO-QAV1': {'Group': 'PECO', 'Version': '10.0.40219'}}, 
        {'MSTQA-ITQA-VM2': {'Group': 'msGrp1', 'Version': '10.0.40219'}}, 
        {'ATM0-IT-QAV2': {'Group': 'IT', 'Version': '10.0.40219'}},
      ]
     }, 
     'DUCPercentages': 
      {'List hardware': 
        {'Not installed': {'Percentage': '18.2', 'Count': 2}, 
         '10.0.40219': {'Percentage': '81.8', 'Count': 9}
        }
      }
    }

期望输出:

reuslt = {'IndividualDUC': 
 {'List hardware':
  [
    {'AMDEVBOS': {'Group': 'Default','Version': 'Not installed'}}, 
    {'ATM0-IT-QAV1': {'Group': 'IT', 'Version': 'Not installed'}}, 
    {'ATM0-IT-QAV2': {'Group': 'IT', 'Version': '10.0.40219'}}, 
    {'ATM0-PEO-QAV2': {'Group': 'PECO', 'Version': '10.0.40219'}}, 
    {'ATM0-PEO-QAV1': {'Group': 'PECO', 'Version': '10.0.40219'}},          
    {'MSTQA-ITQA-VM2': {'Group': 'msGrp1', 'Version': '10.0.40219'}}, 
  ]
}, 
'DUCPercentages': 
  {'List hardware': 
    {'Not installed': {'Percentage': '18.2', 'Count': 2}, 
     '10.0.40219':    {'Percentage': '81.8', 'Count': 9}
    }
  }
}

0 个答案:

没有答案