Skip to content Skip to sidebar Skip to footer

Remove Line Break From Each Element In Python

I open a text file, now each element in the text file is separated by a line break. when I use readlines() It keeps this line break in the list, this is after each element so as it

Solution 1:

try:

filelist = [line.rstrip('\n') for line in file]

Post a Comment for "Remove Line Break From Each Element In Python"