Use sorted function with a custom key function:-
sorted(string_name, key=order)
A custom key function is supplied to customize the sort order of the function. i.e. now characters will be sorted in
23456789JQKA
this order.
EXAMPLE
order = "23456789JQKA"
print(*sorted("KA2J32535", key=order.index),sep='')
OUTPUT
223355JKA
P.S.:- I have converted the result into a string, if you don’t want such you can remove the *
and sep=''
from the print()
1
solved Specific Order Sorting within a List