import math


def data_to_sorted_xy(data, logx):
    """
    Return a list of (x, y) pairs with distinct x values and sorted by x value.

    Enter: data: a list of (x, y) or [x, y] values.
           logx: True to return (log10(x), y) for each entry.
    Exit:  data: the sorted list with unique x values.
    """
    if not logx:
        if (len(data) <= 1 or (
                data[0][0] < data[1][0] and (len(data) <= 2 or (
                data[1][0] < data[2][0] and (len(data) <= 3 or (
                data[2][0] < data[3][0] and len(data) == 4)))))):
            return data
        return sorted(dict(data).items())
    return sorted({math.log10(x): y for x, y in data}.items())