繁体   English   中英

在字典列表中形成字典列表理解

[英]Forming List Comprehension For Dictionary Inside a List of Dictionaries

我有一个webservice json响应,它是一个字典列表,值本身就是字典。 如下例所示:

[
 {
   "ET": {
          "application_environment": "Y",
          "period_process": "Y",
          "extended_options": "N",
          "reports": "Y",
          "administration_tasks": "N",
          "daily_process": "Y",
          "inquiry": "Y"
          }
 },
 {
   "SD": {
           "daily_process": "Y",
           "authorize_cashier_to_close_warranty": "Y",
           "authorize_to_update_technicians_cost": "Y",
           "authorize_to_booking": "Y",
           "authorize_to_policy_adjustments": "Y",
           "authorize_to_pre-paid_maintenance_packages": "Y",
           "authorize_to_enter_actual_time": "Y"
          }
  }
]

我有以下哪些有用,我只是想知道是否有办法用列表理解来做到这一点?

    parsed_response = response.json()
    from_svc = []
    for items in parsed_response:
        for values in items.values():
            for daily_process in values.get("daily_process"):
                from_svc.append(daily_process)

我想这就是你要找的东西?

[ values['daily_process'] for items in parsed_response 
                              for values in items.values() ]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM