deep_throat.py 文件源码

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

项目:deep_throat 作者: wdbm 项目源码 文件源码
def match_and_replace(
    text    = None,
    rule    = None,
    phoneme = None
    ):
    """
    Replace found text from a single rule.
    """
    # Find all rule matches.
    matches = [(match.start(), match.end()) for \
        match in re.finditer(rule, text)]
    # Start from behind, so replace in-place.
    matches.reverse()
    # Convert to characters because strings are immutable.
    characters = list(text)
    for start, end in matches:
        characters[start:end] = phoneme
    # Convert back to string.
    return "".join(characters)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号