title: Remove leading/ending and internal multiple spaces but NOT tabs, newlines, or return characters, in Python
body: <p>The answer to the question at <a href="https://stackoverflow.com/questions/8270092/python-remove-all-whitespace-in-a-string/28607213">Python remove all whitespace in a string</a> shows separate ways to remove leading/ending, duplicated, and all spaces, respectively, from a string in Python. But strip() removes tabs and newlines, and lstrip() only affects leading spaces. The solution using .join(sentence.split()) also appears to remove Unicode whitespace characters. </p>
  
  <p>Suppose I have a string, in this case scraped from a website using Scrapy, like this:</p>
  
  <pre><code>['\n                        \n                    ',
           '\n                        ',
           'Some text',
           ' and some more text\n',
    ' and on another a line some more text', '
                  ']
  </code></pre>
  
  <p>The newlines preserve formatting of the text when I use it in another contexts, but all the extra space is a nuisance. <strong>How do I remove all the leading, ending, and duplicated internal spaces while preserving the newline characters (in addition to any \r or \t characters, if there are any)?</strong> </p>
  
  <p>The result I want (after I join the individual strings) would then be:</p>
  
  <pre><code>['\n\n\nSome text and some more text\nand on another line some more text']
  </code></pre>
  
  <p>No sample code is provided because what I've tried so far is just the suggestions on the page referenced above, which gets the results I'm trying to avoid.</p>