首页 > 解决方案 > 如何从字典python列表中获取所有id

问题描述

我有以下来自 json 文件的结果。我想从字典列表中获取所有 id

result = { 
           "response": [{
             "1d": 1, 
             "name": "jhon"
           },  
           {
             "1d": 2, 
             "name": "tom"
           }, 
           {
             "1d": 3, 
             "name": "peter"
           }
         ]}

预期结果:[1, 2, 3]

标签: python

解决方案


print ([value['1d'] for value in result['response'] ])

推荐阅读