__init__.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:scarlett_os 作者: bossjones 项目源码 文件源码
def ensure_unique_string(preferred_string: str, current_strings:
                         Union[Sequence[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 = "{}_{}".format(preferred_string, tries)

    return test_string


# Taken from: http://stackoverflow.com/a/11735897
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号