I have an array like this:
master = ['aa','bb','cc','dd','ee','ff']
I need to sort it according to this:
order = ['c','e','a','b']
So the final answer would look like:
['cc','ee','aa','bb','dd','ff']
The problem is that if the item is not in the order array then it would go to the end, and I'm not sure how to do that.
How would you approach this? I tried:
master.sort(key=lambda x: order.index(x))
But it will crash if x
is not in the order
array, for example 'dd'
and 'ff'