def paragraphs_from_lines(lines, splitchar='\n', break_on_num_newlines=2, force_unix_linebreaks=True):
    """
    Take string of `lines`, split into list of lines using `splitchar` (or don't if `splitchar` evaluates to False) and
    then split them into individual paragraphs. A paragraph must be divided by at
    least `break_on_num_newlines` line breaks (empty lines) from another paragraph.
    Return a list of paragraphs, each paragraph containing a string of sentences.
    """
    if splitchar:
        if force_unix_linebreaks:
            lines = linebreaks_win2unix(lines)

        lines = lines.split(splitchar)
    else:
        if type(lines) not in (tuple, list):
            raise ValueError("`lines` must be passed as list or tuple if `splitchar` evaluates to False")

    n_lines = len(lines)
    paragraphs = []
    n_emptylines = 0
    cur_par = ''
    # iterate through all lines
    for i, l in enumerate(lines):
        if not splitchar and force_unix_linebreaks:
            l = linebreaks_win2unix(l)

        if l.strip():
            if not cur_par:
                cur_par = l
            else:
                cur_par += ' ' + l
            n_emptylines = 0
        else:
            n_emptylines += 1

        if (n_emptylines >= break_on_num_newlines-1 or i == n_lines-1) and cur_par:
            paragraphs.append(cur_par)
            cur_par = ''
            n_emptylines = 0

    return paragraphs
def paragraphs_from_lines ( lines , splitchar = '\n' , break_on_num_newlines = 2 , force_unix_linebreaks = True ) : if splitchar : if force_unix_linebreaks : lines = linebreaks_win2unix ( lines ) lines = lines . split ( splitchar ) else : if type ( lines ) not in ( tuple , list ) : raise ValueError ( "`lines` must be passed as list or tuple if `splitchar` evaluates to False" ) n_lines = len ( lines ) paragraphs = [ ] n_emptylines = 0 cur_par = '' for i , l in enumerate ( lines ) : if not splitchar and force_unix_linebreaks : l = linebreaks_win2unix ( l ) if l . strip ( ) : if not cur_par : cur_par = l else : cur_par += ' ' + l n_emptylines = 0 else : n_emptylines += 1 if ( n_emptylines >= break_on_num_newlines - 1 or i == n_lines - 1 ) and cur_par : paragraphs . append ( cur_par ) cur_par = '' n_emptylines = 0 return paragraphs
Take string of `lines`, split into list of lines using `splitchar` (or don't if `splitchar` evaluates to False) and
    then split them into individual paragraphs. A paragraph must be divided by at
    least `break_on_num_newlines` line breaks (empty lines) from another paragraph.
    Return a list of paragraphs, each paragraph containing a string of sentences.