简体   繁体   English

提取嵌套字典的内部值

[英]extract inner values of a nested dictionary

I have a nested dictionary A and trying to collect all inner values which are basically the float numbers.我有一个嵌套的字典 A 并试图收集所有基本上是浮点数的内部值。

A={0:{1:2.3, 2:4.3, 6:2.1}, 1:{3:2.6, 4:4.1, 6:8.1}, 3:{0:2.2, 2:9.3, 4:3.1},5:{1:2.8, 2:5.3, 6:2.1}}

I am using我在用

col=[A[key][values] for values in A[key]]

but this only gives the inner values of key=0但这仅给出 key=0 的内部值

Do you know why this happen and what should be the approach I get a get all inner values?你知道为什么会发生这种情况吗,我应该采用什么方法来获得所有内在价值?

Try this:尝试这个:

[x for y in A.values() for x in y.values() ]

Output:输出:

[2.3, 4.3, 2.1, 2.6, 4.1, 8.1, 2.2, 9.3, 3.1, 2.8, 5.3, 2.1]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM