gpt4 book ai didi

arrays - 如何提取字典键中的键

转载 作者:行者123 更新时间:2023-12-03 01:37:38 24 4
gpt4 key购买 nike

我有以下结构:

mappings": {
"go": {
"_ttl": {something goes here},
"symbol": {},
"associationType.keyword": {},
"go_genes": {},
"go_species.keyword": {},
"symbol.autocomplete": {},
"primaryId": {},
"href.keyword": {},
"name_key": {},
"symbol.sort": {},
"name_key.keyword": {},
"go_type.keyword": {},

现在,我有兴趣提取如下内容:
mappings.go.-ttl
mappings.go.symbol
mappings.go.geo_genes
.....

这是我编写的代码,但只给我“go”和其他位置与go相似的节点,这些未在图片中显示。我如何修改它以获得所需的居所描述的结果:
index = "site_index_stage"
elastic_url = "http://localhost:9200"
mapping_fields_request = "_mapping/field/*"
mapping_fields_url = "/".join([elastic_url, index, mapping_fields_request])
response = requests.get(mapping_fields_url)
print(response)
data = response.content.decode()
parsed_data = json.loads(data)
for key in parsed_data[index]['mappings']:
print(key)

最佳答案

最后,这是我的操作方法:

def nested_dict_iter(nested):
for key, value in nested.items():
# print((key,value))
if type(value)==type({}):
for x in value:
output.write(key+'.'+x)
output.write('\n')
nested_dict_iter(parsed_data[index]['mappings'])

关于arrays - 如何提取字典键中的键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51087759/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com