(proposed: list, return_duplicated=False)
return new_names
Returns list of unique names. If a name is duplicated, the
    function appends the next available index in parentheses.

    For example, a proposed list of names `x`, `x` and `x (2)`
    results in `x (3)`, `x (4)`, `x (2)`.
Returns list of unique names. If a name is duplicated, the
    function appends the next available index in parentheses.
Returns list of unique names . If a name is duplicated the function appends the next available index in parentheses .
def get_unique_names_duplicates(proposed: list, return_duplicated=False) -> list:
    """
    Returns list of unique names. If a name is duplicated, the
    function appends the next available index in parentheses.

    For example, a proposed list of names `x`, `x` and `x (2)`
    results in `x (3)`, `x (4)`, `x (2)`.
    """
    indices = {name: count(max(get_indices(proposed, name), default=0) + 1)
               for name, cnt in Counter(proposed).items()
               if name and cnt > 1}
    new_names = [f"{name} ({next(indices[name])})" if name in indices else name
                 for name in proposed]
    if return_duplicated:
        return new_names, list(indices)
    return new_names
def get_unique_names_duplicates ( proposed : list , return_duplicated = False ) -> list : indices = { name : count ( max ( get_indices ( proposed , name ) , default = 0 ) + 1 ) for name , cnt in Counter ( proposed ) . items ( ) if name and cnt > 1 } new_names = [ f"{name} ({next(indices[name])})" if name in indices else name for name in proposed ] if return_duplicated : return new_names , list ( indices ) return new_names