python - 在字典中检查字典中python中的特定值
问题描述
我正在使用由多个字典组成的字典:
my_dictt = {0: {'n': 1, 's': 5, 'w': 7, 'e': 3}, 7: {'w': 8, 'e': 0}, 8: {'e': 7}, 1: {'n': 2, 's': 0}, 2: {'s': 1}, 5: {'n': 0, 's': 6}, 6: {'n': 5}, 3: {'w': 0, 'e': 4}, 4: {'w': 3}}
我需要检查任何嵌套值中的任何值是否为“?”,但无法这样做。我尝试遍历字典并使用 dict.values() 函数,但到目前为止还没有让它工作。有谁知道我怎么能做到这一点?
解决方案
我不知道这是否正是您正在寻找的。在评论中让我知道。
my_dictt = {0: {'n': 1, 's': 5, 'w': 7, 'e': 3}, 7: {'w': 8, 'e': 0}, 8: {'e': 7}, 1: {'n': 2, 's': 0}, 2: {'s': 1}, 5: {'n': 0, 's': 6}, 6: {'n': 5}, 3: {'w': 0, 'e': 4}, 4: {'w': 3}}
#first go to each value of yor dictionary
for eachValue in my_dictt.values():
#then in each value that are dictionaries get each value again
for eachNestedValue in eachValue.values():
# check if any of values are ?
if eachNestedValue == "?":
print(True)
推荐阅读
- kubernetes - ./kvtctl.sh 处的 vitess 安装失败远程错误:rpc 错误:代码 = 不可用 desc = 传输正在关闭
- jquery - 在溢出隐藏区域中向上滑动的文本效果
- templates - 在 Vue 中跨组件共享模板
- hibernate - Hibernate 中的版本检查
- java - 将 Notes 字段转换为 JsonJavaArray
- c# - 无法选择最佳候选函数。您可能需要在 Postgres 中添加显式类型转换
- java - 安卓弹簧按钮
- opencv - 使用 dlib 检测眼睛地标
- html - 如何在 HTML 和 CSS 中创建固定页脚
- node.js - 如何正确使用 require.js 来要求节点模块?