import re s = 'A B C D \n EF G'print(re.sub(r"[^\S\r\n]{2,}", " ", s))
Standard input is empty
A B C D EF G
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!