How to get rid of multiple whitespace AND account for a newline
<p>Say I have an input of <code>"Hello   my    name  is \\n Bill"</code></p>

<pre><code>my_str = ' '.join(my_str.split())
</code></pre>

<p>So this will join the letters and give me <code>"Hello my name is\nBill"</code> when I print it all on one line. What I want it to print is:</p>

<pre><code>Hello my name is
Bill
</code></pre>

<p>to the terminal.</p>

<p>You problem is you don't have a newline char, you have two <em>backslashes</em> and an <code>n</code> i.e the backslash is escaped so after splitting you need to do a replace:</p>

<pre><code>In [10]: s = "Hello   my    name  is \\n Bill"

In [11]: print(" ".join(s.split()))
Hello my name is \n Bill

In [12]: print(" ".join(s.split()).replace("\\n","\n"))
Hello my name is 
 Bill
</code></pre>

<p>Or use <em>.decode("string_escape")</em>:</p>

<pre><code>In [15]: s = "Hello   my    name  is \\n Bill"

In [16]: print" ".join(s.split())
Hello my name is \n Bill

In [17]: print(" ".join(s.split()).decode("string_escape"))
Hello my name is 
 Bill
</code></pre>

<p>As Kirby mentioned in a comment, if you are creating the strings don't escape the backslash, if the data is from another source use one of the methods above.</p>

python whitespace removing-whitespace