you could use file.read(), rather than readlines(), and then you wouldn't need to put the lines back together. (.split() will spilt on any whitespace, including newlines).