removing extra blank spaces in python
Question: I have a file which reads:

    
    
    o hi! My name is Saurabh.
    
    
    
    
    o I like python.
    

I want something like:

    
    
    o hi! My name is Saurabh.
    
    o I like python.
    

I tried the line:

    
    
    removedSpaces=' '.join(lineWithSpaces.split())
    

Looks like it removes all the spaces

It gives me

    
    
    o hi! My name is Saurabh.o I like python. 
    

Which is incorrect. Is it possible to achieve the above output by anyway.


Answer: 
    import re
    removedSpaces = re.sub(r'\n{3,}', "\n\n", lineWithSpaces)
    

This converts all runs of three and more newlines to two newlines.

