import collections


def reorder(fields, order, key):
    """
    Reorders `fields` list sorting its elements in order they appear in `order` list.
    Elements that are not defined in `order` list keep the original order.

    :param fields: elements to be reordered
    :param order: iterable that defines a new order
    :param key: a function of one argument that is used to extract a comparison key from each element in `fields`
    :return: reordered elements list
    """

    ordered = collections.OrderedDict()
    for field in fields:
        ordered[key(field)] = field

    for ord in reversed(order or ()):
        ordered.move_to_end(ord, last=False)

    return ordered.values()