码迷,mamicode.com
首页 > 其他好文 > 详细

将文本按行标识符进行分割

时间:2019-04-12 12:08:07      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:with   def   line   condition   rip   for   false   文本   note   

def split_docs(lines, separator):
    """
    :note: The English sentence is in the front,
        the Chinese sentence is in the back,
        and the two are separated by a separator.
    """
    if not lines:
        return [], []

    eng_lines = []
    chn_lines = []

    chn_begin_condition = False
    for line in lines:
        if chn_begin_condition:
            chn_lines.append(line)
        else:
            chn_begin_condition = line.lstrip().startswith(separator)
            if not chn_begin_condition:
                eng_lines.append(line)

    return eng_lines, chn_lines

 

将文本按行标识符进行分割

标签:with   def   line   condition   rip   for   false   文本   note   

原文地址:https://www.cnblogs.com/wenlin-gk/p/10694977.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!