python - 在 python 字典中搜索所有值
问题描述
我正在用python做一个解析器。但我不知道如何在字典结构中一路向下搜索。
可以说我希望能够获取所有包含 None 的值。
{data01: 'full', data02:'None', data03:'high', data04:'None'}
我尝试过以下方法:
if None in inputfromjson.values():
excludekey
解决方案
通过这种方式,您可以找出所有为 None 的键。
a = {'data01': 'full', 'data02': None, 'data03': 'high', 'data04': None}
for key,value in a.items():
if value == None:
print(key)
a.items() 是一个容器,它返回一个元组,包含键及其对应的值。
推荐阅读
- selenium-webdriver - WebDriver Sampler:调用 threadStarted java.lang.IllegalStateException 时出错:进程尚未退出,因此没有可用的结果
- azure - 打开 Azure Web App for Containers 端口?
- amazon-web-services - 流式视频中的人脸识别每秒仅返回一帧
- database - 用于 Oracle DB 更改的 Redis 侦听器
- javascript - React - 父母没有将方法传递给孩子
- mobile - 让 Google Apps 脚本在移动设备上运行
- c++ - 如何将函数用作变量c ++
- c - 为什么这个浮点数有 2 个不同的值?
- javascript - 当javascript返回为真时如何重定向页面?
- azure - Azure Functions 和 webapp 可以共享同一个 APP SERVICE PLAN