title: Python: Removing whitespace from multiple lines of a string
body: <p>So I need the output of my program to look like:</p>
  
  <pre><code>ababa
  ab ba 
   xxxxxxxxxxxxxxxxxxx
  that is it followed by a lot of spaces .
   no dot at the end
  The largest run of consecutive whitespace characters was 47.
  </code></pre>
  
  <p>But what I am getting is:</p>
  
  <pre><code>ababa
  
  ab ba
  
  xxxxxxxxxxxxxxxxxxx
  that is it followed by a lot of spaces .
  no dot at the end
  The longest run of consecutive whitespace characters was 47.
  </code></pre>
  
  <p>When looking further into the code I wrote, I found with the <code>print(c)</code> statement that this happens:</p>
  
  <pre><code>['ababa', '', 'ab           ba ', '', '                                      xxxxxxxxxxxxxxxxxxx', 'that is it followed by a lot of spaces                         .', '                                               no dot at the end']
  </code></pre>
  
  <p>Between some of the lines, theres the <code>, '',</code>, which is probably the cause of why my print statement wont work.</p>
  
  <p>How would I remove them? I've tried using different list functions but I keep getting syntax errors. </p>
  
  <p>This is the code I made:</p>
  
  <pre><code>  a = '''ababa
  
      ab           ba 
  
                                        xxxxxxxxxxxxxxxxxxx
  that is it followed by a lot of spaces                         .
                                                 no dot at the end'''
  
  
  c = a.splitlines()
  print(c)
  
  #d = c.remove(" ") #this part doesnt work
  #print(d)
  
  for row in c:
      print(' '.join(row.split()))
  
  last_char = ""
  current_seq_len = 0
  max_seq_len = 0
  
  for d in a:
      if d == last_char:
          current_seq_len += 1
          if current_seq_len &gt; max_seq_len:
              max_seq_len = current_seq_len
      else:
          current_seq_len = 1
          last_char = d
      #this part just needs to count the whitespace
  
  print("The longest run of consecutive whitespace characters was",str(max_seq_len)+".")
  </code></pre>