working_with_tokens.py 文件源码

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

项目:diff-highlight-tokens 作者: Met48 项目源码 文件源码
def convert_to_lines(tokens):
    """
    Given a stream of tokens, yield lines as strings.

    Each output string is guaranteed to end with a newline.

    """
    line = []
    for token in tokens:
        text = get_token_text(token)
        line.append(text)
        if text == '\n':
            yield ''.join(line)
            line = []
    if line:
        line.append('\n')
        yield ''.join(line)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号