sentences = itertools.groupby(text, lambda x: any(x.endswith(punct) for
    punct in endsentence))
for number, (truth, sentence) in enumerate(sentences):
    if truth:
        first_n_sentences = previous + ''.join(sentence).replace('\n', ' ')
previous = ''.join(sentence)
if number >= 2 * n:
    break
return first_n_sentences
How to break up a paragraph by sentences in Python