Reputation: 71
I have a nested dictionary A and trying to collect all inner values which are basically the float numbers.
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
Do you know why this happen and what should be the approach I get a get all inner values?
Upvotes: 1
Views: 112
Reputation: 2025
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]
Upvotes: 3