skbase.utils.make_strings_unique#
- skbase.utils.make_strings_unique(str_list: Tuple[str, ...]) Tuple[str, ...][source]#
- skbase.utils.make_strings_unique(str_list: List[str]) List[str]
Make a list or tuple of strings unique by appending number of occurrence.
Supports making string elements unique for nested list/tuple input.
- Parameters:
- str_listnested list/tuple structure with string elements
The list or tuple with string elements that should be made unique.
- Returns:
- list[str] | tuple[str]
The input strings coerced to have unique names.
If no duplicates then the output list/tuple is same as input.
Otherwise, the integer number of occurrence is appended onto duplicate strings. If this results in duplicates (b/c another string in input had the name of a string and integer of occurrence) this is repeated until no duplicates exist.
Examples
>>> from skbase.utils import make_strings_unique >>> some_strs = ["abc", "abc", "bcd"] >>> make_strings_unique(some_strs) ['abc_1', 'abc_2', 'bcd'] >>> some_strs = ["abc", "abc", "bcd", "abc_1"] >>> make_strings_unique(some_strs) ['abc_1_1', 'abc_2', 'bcd', 'abc_1_2']