Santosh Kumar wrote: > I am in a problem. > > words = line.split(' ') > > preserve whitespaces but the problem is it writes an additional line > after every line. Strip off the newline at the end of the line with: line = line.rstrip("\n") words = line.split(" ")