I have a list of class instances like so:
classes = [A(someval), B(someval), C(someval)]
I would like to sort this list using a "master" list.
master_list = [B, A]
This would sort the list with B
and A
first if they exist and always in the order specified in master_list
. The classes are field validators so I expect there never to be more than one of each class, but one can never know for sure.
Any other class instances can just come after in any order they appear.
I would like to be able to put some instances at the end of the list according to another master list, but I suspect the best this to do here is just reverse the list and do the same thing again.
But how do I do it?
Edit: Subclasses are not important as these validator classes only have a single callable method and are generally pretty simple beasts. I have yet to encounter a subclassed validator and I have tried to imagine a scenario where it would be beneficial, but I cannot.