import sys while True: while True: c = sys.stdin.read(1) if c != ' ': break # skip leading spaces while c != '' and c > ' ': sys.stdout.write(c) # print non-spaces c = sys.stdin.read(1) while c != '' and c != '\n': # skip all trailing characters c = sys.stdin.read(1) if c == '': break # stop at EOF sys.stdout.write(c)