def shorten_unique(names, keep_first=4, keep_last=4):
    """
    Shorten strings, inserting '(...)', while keeping them unique.

    Parameters
    ----------
    names: List[str]
        list of strings to be shortened
    keep_first: int
        always keep the first N letters
    keep_last: int
        always keep the last N letters

    Returns
    -------
    shortened_names: List[str]
        list with shortened strings
    """
    short, cut_chars, longest_str = [], 0, max([len(p) for p in names])
    while len(set(short)) != len(set(names)) and cut_chars <= longest_str:
        short = [p[:keep_first + cut_chars] + '(...)' + p[-keep_last:]
                 if len(p) > sum([keep_first, keep_last, cut_chars])
                 else p for p in names]
        cut_chars += 1
    return short