from typing import Union
from typing import Iterable
from typing import KeysView


def ensure_unique_string(
    preferred_string: str, current_strings: Union[Iterable[str], KeysView[str]]
) -> str:
    """Return a string that is not present in current_strings.

    If preferred string exists will append _2, _3, ..
    """
    test_string = preferred_string
    current_strings_set = set(current_strings)

    tries = 1

    while test_string in current_strings_set:
        tries += 1
        test_string = f"{preferred_string}_{tries}"

    return test_string