python-3.x - 选择dict数组中的键
问题描述
您将如何从 python 3.x 中的 dict 数组中选择键和值?
输入:
[
{
"type": "update", "name":"joe"
},
{
"type": "new", "name":"matthew"
}
]
期望的输出:
[
{
"name":"joe"
},
{
"name":"matthew"
}
]
解决方案
假设您想要'name'
键及其值:
[{'name': item['name']} for item in original if 'name' in item]
推荐阅读
- mariadb - maria db galera 集群 - 安装后缺少 wsrep 提供程序
- php - 如何在 HostGator cpanel 上的 codeigniter 中设置 cron 作业 url
- javascript - 仅提交填充的文本框值并丢弃空文本框 ih form php
- tensorflow - 当层的权重不是正态分布时是什么意思
- css - 在 Stylus 迭代中使用 CSS 变量
- java - 从字面上构建我自己的多维锯齿状阵列
- python - 气流 - 松弛通知。当我的程序使用气流失败时,我正在尝试配置松弛通知
- laravel-5 - 如何在 Laravel 5.6 应用程序中突出显示当前活动菜单?
- c - C hsearch 查找操作总是返回错误的数据值但正确的键值
- laravel-5 - 如何在 laravel 中修改请求文本