python - 有没有比这更 Pythonic 的方法来遍历字典键以查找值?
问题描述
这是一个示例字典,colors
:
{
"Red" : {
"members" : {
"153950039532134112" : {
"rank" : 1,
"score" : 43,
"time" : 1530513303
}
},
"rank" : 2,
"score" : 43
},
"Blue" : {
"members" : {
"273493248051539968" : {
"rank" : 1,
"score" : 849,
"time" : 1530514923
},
"277645262486011904" : {
"rank" : 2,
"score" : 312,
"time" : 1530513964
},
"281784064714487810" : {
"rank" : 3,
"score" : 235,
"time" : 1530514147
}
},
"rank" : 1,
"score" : 1396
}
}
为了这个例子,让我们假设这个字典中有更多的颜色命名键。现在,假设我正在寻找一个特定的会员 ID。
for key, value in colors.items():
if member_id in value['members']:
return True
有没有更简单的,可能是单行的方法来做到这一点?
解决方案
推荐阅读
- spring-boot - @Valid for long 数据类型不适用于强制检查
- mysql - MySQL中带有'SET'的两个表之间的多列更新
- octave - Octave 5.1.0 不再支持将图形复制到剪贴板
- python - Databricks CSV 多次读取
- java - android studio中的appLocale设置
- c# - 如何在同一个集合的多个 MongoDB 观察者之间分配工作负载?
- java - 为什么使用 onPrepareOptionsMenu 创建一个菜单,其中布局文件出现在屏幕顶部,而运行时出现在底部?
- java - 如何在不使方法非静态的情况下增加 numDigits?
- excel - https://scra.dmdc.osd.mil/scra/#/home 上的多条记录请求
- java - 在字符数组中查找和拼凑分散的单词