提问人:LV_Node23 提问时间:9/28/2023 更新时间:9/28/2023 访问量:7
遍历字典列表并仅打印具有特定值的项目?
Loop through a list of dictionaries and print only those items with specific value?
问:
这里的新手:)我的任务是只打印字典列表中状态为“墓碑”的那些项目。下面是列表的示例:
配置 =
“配置”:[ { “_id”: “my_ID3”, “channel_name”: “我爱露西”, “content_owner”: “新 ID”, “country”: “美国”, “service_id”: “ABCD”, “status”: “准备测试” }, { “_id”: “my_ID2”, “channel_name”: “大金刚”, “content_owner”: “新 ID”, “country”: “美国”, “service_id”: “EFG”, “status”: “准备测试” }, { “_id”: “my_ID1”, “channel_name”: “吃豆人”, “content_owner”: “Pac Productions”, “country”: “美国”, “service_id”: “1234”, “status”: “日落” }
在 Python 中浏览列表并仅打印状态为“Sunset”的通道 ID(包含所有配置)的最佳方法是什么?注意:还有其他状态,但只需要删除那些具有“日落”的状态。希望以上信息足以帮助解释所需的步骤。感谢您的帮助:)
目前,仍在试图找出方法。
对于 configs 中的配置: if “status” != “日落” 返回配置
打印(config[_id], config[channel_name, config[content_owner], config[国家],config[service_id],config[状态]
预期结果: 目标是仅打印那些没有“日落”的通道配置 { “_id”: “my_ID3”, “channel_name”: “我爱露西”, “content_owner”: “新 ID”, “country”: “美国”, “service_id”: “ABCD”, “status”: “准备测试” }, { “_id”: “my_ID2”, “channel_name”: “大金刚”, “content_owner”: “新 ID”, “country”: “美国”, “service_id”: “EFG”, “status”: “准备测试”
答: 暂无答案
评论