Given: Assume you have a following text file (sample.txt).
Line1 line2 line3 line4 line5
Expected Output:
Hint:
replace()
\n
' '
Solution:
with open('sample.txt', 'r') as file: data = file.read().replace('\n', ' ') print(data)
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Hint:
replace()
function to replace all newlines (\n
) with space (' '
).Solution:
replace()
function to replace all newlines (\n
) with space (' '
).