def pattern_sort(lst, pattern, key=None, reverse=False):
    """sorts lst based on pattern
    (e.g. ```pattern_sort(['a','ba','c'], [2, 0, 1], lambda x: len(x))``` would return ```['ba','a','c']```)

    lst: the list to sort \\
    pattern: the pattern to sort with
    (list of numbers, i.e. ```[2, 1, 0]``` would swap the 2th element with the 0th element) \\
    key: sorting key to sort initially before sorting using the pattern (function) \\
    reverse: whether to sort backwards during initial sort (bool)
    """
    lst.sort(key=key, reverse=reverse)
    zip_list = zip(lst, pattern)
    return [ele for ele, _ in sorted(zip_list, key=lambda x: x[1])]