frazman
frazman

Reputation: 33263

sort a dictionary by inner key python

I have a 3 dimensional dictionary

 d = ({k1:{k2:{k3:v}}}
       and many more such keys....)

Now, I want to sort this dictionary by k3? What is the best way to do this?

Upvotes: 0

Views: 186

Answers (1)

Joran Beasley
Joran Beasley

Reputation: 113998

 sorted_keys = sorted(d.keys(),key=lambda x:d[x]['key2']['key3'])

will sort the keys for you ... (since dictionaries are by definition unsorted)

Upvotes: 3

Related Questions