Q:

how to concatenate file line sentence in one string in python?

hi i am learning python please help me
I am reading a file, line-by-line and i want output for line of words in one String:
for Example 
input file name file.txt and content have file below mentation
Y
X   Y
K   Y
L   Y
expected output
Y
XY
KY
LY

A:

You can do so with following code:
with open('file.txt') as input_file:
    for line in input_file:
        print ''.join(line.split())

split will create a list of words by breaking the line at every space and join will merge items in a list in to a string.

