import res = 'I love to eat cake'print( re.sub(r'\s{2,}', lambda x: '-' * len(x.group()), s) )
Standard input is empty
I love---to eat----cake
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!