macpie.strtools.make_unique#
- macpie.strtools.make_unique(seq, suffs_iter=None, suffs_prefix='', suffs_suffix='', skip=0, skip_suffix='', inplace=False)#
Make sequence of string elements unique by adding a differentiating suffix.
- Parameters:
- seqSequence
Mutable sequence of strings
- suffs_iteroptional, default is itertools.count(1)
An alternative iterable of suffixes
- suffs_prefixoptional, default is empty string
An alternative string to prepend to each suffix in
suffs_iter
- suffs_suffixoptional, default is empty string
An alternative string to append to each suffix in
suffs_iter
- skipoptional, default is 0
How many duplicates to skip before appending suffixes.
- skipped_suffixoptional, default is empty string
Add this suffix to any skipped duplicates.
- inplaceoptional, default is False
Whether to modify the list in place
Examples
>>> lst = ["name", "state", "name", "city", "name", "zip", "zip"] >>> make_unique(lst) ["name1", "state", "name2", "city", "name3", "zip1", "zip2"]
>>> make_unique(lst, skip=1) ["name", "state", "name1", "city", "name2", "zip", "zip1"]
>>> make_unique(lst, suffs_prefix="_") ["name_1", "state", "name_2", "city", "name_3", "zip_1", "zip_2"]