Q:

How to sort list of dicts by dict value in pre-defined format?

I've got a list of dicts which describe certain classes in a school of which some are still taught, some are not anymore, and some are going to be taught in the future:
[
    {'status': 'DEACTIVE', 'name': 'Music'},
    {'status': 'DEACTIVE', 'name': 'Juggling'},
    {'status': 'ACTIVE', 'name': 'Chess'},
    {'status': 'ACTIVE', 'name': 'Dutch Language'},
    {'status': 'COMING', 'name': 'Python'},
    {'status': 'COMING', 'name': 'Drinking coffee like a pro'},
]

I now want to order this list so that the ACTIVE are first, then the DEACTIVE, and finally the COMING. I found solutions such as this:
sorted(a, key=dict.values, reverse=True)

but that only orders it by alphabet where I want to sort it in a custom way. Does anybody know how I can do this?

A:

You can do it using dictionary with weight of all statuses:
STATUS_RANK = {"ACTIVE": 1, "DEACTIVE": 2, "COMING": 3}

courses.sort(key=lambda x: STATUS_RANK[x['status']])

