Question: I have a dictionary of dictionaries like the following

```
d = {
  'hain': {'facet': 1, 'wrapp': 1, 'chinoiserie': 1}, 
  'library': {'sconc': 1, 'floor': 1, 'wall': 2, 'lamp': 6, 'desk': 1, 'table': 1, 'maine': 1} 
}

```

So, I want to reverse sort this dictionary based on the ultimate value:

so what I am expecting is to print out something like this:

```
  key_1,   key_2 , value
 library   lamp      6
 library   wall      2

```

and so on...

How do i get this?

Thanks

Answer: 
If you want it sorted first be reverse sorted by `value` then ascending sorted by `key` then `key_2`:

```
dout={}
for e in d:
    for es in d[e]:
        lineOut='%s %s %i' % (e, es, d[e][es])
        key= d[e][es]
        dout.setdefault(key, []).append(lineOut)  

for e in sorted(dout, reverse=True):
    for ea in sorted(dout[e], reverse=False):
        print ea         

```

prints:

```
library lamp 6
library wall 2
hain chinoiserie 1
hain facet 1
hain wrapp 1
library desk 1
library floor 1
library maine 1
library sconc 1
library table 1

```
I'm not sure exactly how you want the output sorted, but this should get you started:

```
>>> for key in d:
        for key2 in d[key]:
            print key, key2, d[key][key2]

```