I am trying to sort the List using dictionary keys in ascending order.
You can assume just one key per dictionary level.
Input:
res = [{'hi': {'abc': 5}}, {'bye': {'def': 5}}, {'hi': {'cba': 5}}]
My Code:
def getitem (item):
return (item.keys())
print (sorted(res, key = getitem))
Required Output:
[{'bye': {'def': 5}}, {'hi': {'abc': 5}}, {'hi': {'cba': 5}}]
dict.keysobjects are for subset relationship