How to use text.split() and retain blank (empty) lines
<p>New to python, need some help with my program. I have a code which takes in an unformatted text document, does some formatting (sets the pagewidth and the margins), and outputs a new text document. My entire code works fine except for this function which produces the final output. </p>

<p>Here is the segment of the problem code:</p>

<pre><code>def process(document, pagewidth, margins, formats):
    res = []
    onlypw = []
    pwmarg = []
    count = 0
    marg = 0


    for segment in margins: 

        for i in range(count, segment[0]):
            res.append(document[i])
        text = ''

    foundmargin = -1
    for i in range(segment[0], segment[1]+1):
        marg = segment[2]
        text = text + '\n' + document[i].strip(' ')

    words = text.split()
</code></pre>

<p>Note: segment [0] means the beginning of the document, and segment[1] just means to the end of the document if you are wondering about the range. My problem is when I copy text to words (in words=text.split() )  it does not retain my blank lines. The output I should be getting is:</p>

<pre><code>      This is my substitute for pistol and ball. With a
      philosophical flourish Cato throws himself upon his sword; I
      quietly take to the ship. There is nothing surprising in
      this. If they but knew it, almost all men in their degree,
      some time or other, cherish very nearly the same feelings
      towards the ocean with me.

      There now is your insular city of the Manhattoes, belted
      round by wharves as Indian isles by coral reefs--commerce
      surrounds it with her surf.
</code></pre>

<p>And what my current output looks like:</p>

<pre><code>      This is my substitute for pistol and ball. With a
      philosophical flourish Cato throws himself upon his sword; I
      quietly take to the ship. There is nothing surprising in
      this. If they but knew it, almost all men in their degree,
      some time or other, cherish very nearly the same feelings
      towards the ocean with me. There now is your insular city of
      the Manhattoes, belted round by wharves as Indian isles by
      coral reefs--commerce surrounds it with her surf. 
</code></pre>

<p>I know the problem happens when I copy text to words, since it doesn't keep the blank lines. How can I make sure it copies the blank lines plus the words?
Please let me know if I should add more code or more detail!</p>
