I have a list and the last list item has a \n
which I don't want.
print(list)
[somebody,please,help\n] #what I have
print(list)
[somebody,please,help] #desired list
I have a list and the last list item has a \n
which I don't want.
print(list)
[somebody,please,help\n] #what I have
print(list)
[somebody,please,help] #desired list
You can use the strip function to remove any white space characters from the ends of the string for example:
str = str.strip()
So before printing, strip the string. Perhaps you can save the stripped strings in a new list.
str.strip() will remove the white space chars from the ends of the string. Don't forget that strip() returns a new string which needs to be assigned... You probably want.
for element in list:
element = element.strip()