Python嵌套词典中的旁路顶键以提取低级键
我有一个复杂的嵌套词典。我想提取所有“符号”键。我已经尝试了提取所有值的功能,以获取所有值,转换为列表,元组,我知道我可以一小段分解它,但是我想知道什么是最有效,最小的错误的容易出现的方法来解析此<强>不调用顶级键。顶级键更改,因此创建功能来解释这些功能并不理想,并打开了破坏代码的可能性,因此输入symbol = map ['2022-05-10:1''] ['2022-05-10:1'] ['303.0'] ['符号']
不是我要做的。
I have a complex nested dictionary. I want to extract all "symbol" keys. I have tried functions extracting all values, .get, converting to a list, tuples, and I know I could break it down piece by piece, but I would like to know what is the most efficient, least error prone way to parse this without calling the top level keys. Top level keys change so creating functions to account for those is not ideal and opens up the possibility for breaking the code, so entering symbol = map['2022-05-10:1']['303.0']['symbol']
is not what I want to have to do.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请在嵌套词典中获取所有
符号
值
。
Do get all
symbol
values in your nested dictionary you can use next example (dct
is your dictionary from the question):Prints:
EDIT: If there are missing symbols:
如果此结构是指定的,则可以使用:
或仅删除
符号= []
并替换symbers.append(j [“ symend”])
print( j [“符号”])
如果您只想打印符号键而不是保存。If this structure is consitent, you can use:
Or just remove
symbols = []
and replacesymbols.append(j["symbol"])
withprint(j["symbol"])
if you would rather just print the symbol key instead of saving it.