Since dictionary is a collection of randomly arranged pair of key and value you can not actually sort a dictionary itself but yes you can have a sorted view of the dictionary.
Possibly a list generated from the entries in a dictionary.
For example
import operator
x = {'Delhi': ['capital', 'state'],
'Uttar Pradesh': "population",
'Tamil Nadu': ['southern'],
'Assam': ['mountains']}
# To sort dict based on values
sorted_x = sorted(x.items(), key=operator.itemgetter(1))
print(sorted_x)
# To sort dict based on KEYS
sorted_x = sorted(x.items(), key=operator.itemgetter(0))
print(sorted_x)
This has both the solution on how to sort the dictionary based on either key or values.
This returns a list of tuples.
This can be done using lambda functions in the following way -
x = {'Delhi': ['capital', 'state'],
'Uttar Pradesh': "population",
'Tamil Nadu': ['southern'],
'Assam': ['mountains']}
# To sort dict based on KEYS
sorted_x = sorted(x.items(), key=lambda x: x[0])
print(sorted_x)
# To sort dict based on VALUES
sorted_x = sorted(x.items(), key=lambda x: x[1])
print(sorted_x)
Complete working example - http://ideone.com/KzAeG5
Hope it helps.