栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python怎么获取多重嵌套(列里嵌套了字典)的键值对

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python怎么获取多重嵌套(列里嵌套了字典)的键值对

 [{"orig_question": "What position does the player who played for butler cc (ks) play?", "model_output": {"_type": "select", "agg": {"_type": "NoAgg"}, "col": 3, "conds": [{"_type": "cond", "op": {"_type": "Equal"}, "col": 0, "value": "butler cc (ks)"}]}, "inferred_code": {"agg": 0, "sel": 3, "conds": [[0, 0, "butler cc (ks)"]]}, "score": -0.4338613631116459}]

有这么一串数据名为decoded,我需要获取问题是什么,即获取orig_question。那么怎么才能得到呢?

 print(f'您输入的问题为{decoded[0]["orig_question"]}')

可以看到decoded[0]["orig_question"]先取出列里的内容得到了:

 {"orig_question": "What position does the player who played for butler cc (ks) play?", "model_output": {"_type": "select", "agg": {"_type": "NoAgg"}, "col": 3, "conds": [{"_type": "cond", "op": {"_type": "Equal"}, "col": 0, "value": "butler cc (ks)"}]}, "inferred_code": {"agg": 0, "sel": 3, "conds": [[0, 0, "butler cc (ks)"]]}, "score": -0.4338613631116459}

剩下的是字典
然后要根据字典键值对取值

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/884168.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号