Sort a string according to the given order: Anything that doesn’t have an order can be placed at the beginning or the end, so I placed it at the end.
class Solution:
def customSortString(self, order: str, s: str) -> str:
ordering = {c: i + 1 for i, c in enumerate(order)}
return ''.join(sorted(s, key=lambda x: ordering.get(x, 0)))