Sort list containing dictionaries with lists as values

I’m trying to work through the problem below:
list_dict = [{‘pet’:[‘Bird’, ‘Frog’, ‘Hamster’]},
{‘id’: [123, 456, 789]},
{‘dog’: [‘Beagle’, ‘Labrador’, ‘Dalmatian’]}
The challenge is to print the sorted list by the ‘id’ column in descending order.
So far I’ve tried
result1 = sorted(list_dict, key=lambda k: list(k.items())[0])
print(result1) which prints:
[{‘dog’: [‘Beagle’, ‘Labrador’, ‘Dalmatian’]},
{‘id’: [123, 456, 789]},
{‘pet’: [‘Bird’, ‘Frog’, ‘Hamster’]}]

how can I get this to work?


I am very sorry but I really do not understand your list! Have the dogs no IDs? However now i have tried to change you code a little bit and provide you with a solution that hopefully shows you the way how to proceed to find a solution for your challenge.

Hier my proposal:

from operator import itemgetter

pet = [{"animal": "Bird", "id": 123},
       {"animal": "Frog", "id": 456},
       {"animal": "Hamster", "id": 789}

pet.sort(key=itemgetter("id"), reverse=True)


Test it!