def sort(list_, order, key=None):
    """Sorts `list_` by explicitly specified `order`.

    >>> sort(['a', 'b', 'c'],
    ...      ['c', 'b', 'xxx', 'a', 'yyy'])
    ['c', 'b', 'a']

    >>> sort(['a', 'b', 'c', 'd'],
    ...      ['c', 'b', 'a'])
    ['c', 'b', 'a', 'd']

    >>> sort([('a', 1), ('b', 2)],
    ...      ['b', 'a'],
    ...      key=lambda el: el[0])  # Sort tuples by first element
    [('b', 2), ('a', 1)]
    """
    def key_(el):
        k = key(el) if key else el
        if k in order:
            return order.index(k)
        else:
            return len(order) + 1
    return sorted(list_, key=key_)