<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def sort_keys(self, keys, order=QuerySet.ASCENDING):
 """Sort keys. Keys are sorted based on the value they are indexing. :param keys: Keys to be sorted :type keys: list(str) :param order: Order criteri (asending or descending) :type order: int :return: Sorted keys :rtype: list(str) :raise ValueError: If invalid order value is passed """

        # to do: check that all reverse index values are unambiguous
        missing_keys = [
            key
            for key in keys
            if not len(self._reverse_index[key])
        ]
        keys_and_values = [
            (key, self._reverse_index[key][0])
            for key in keys
            if key not in missing_keys
        ]
        sorted_keys = [
            kv[0]
            for kv in sorted(
                keys_and_values,
                key=lambda x: x[1],
                reverse=True if order == QuerySet.DESCENDING else False)
        ]
        if order == QuerySet.ASCENDING:
            return missing_keys + sorted_keys
        elif order == QuerySet.DESCENDING:
            return sorted_keys + missing_keys
        else:
            raise ValueError('Unexpected order value: {:d}'.format(order))