How to remove newline character from a list in Python

Removing newline characters from a list of strings modifies the list to exclude the newline characters from each element. For example, removing newline characters from the list [“a”, “b\n”, “c\n”] results in [“a”, “b”, “c”].

Solution for How to remove newline character from a list in Python : You can use str.strip() to remove newline characters from a list Use a for-loop to iterate through the elements of a list, and call str.strip() with str as each element to return a copy of the element with leading and trailing whitespace as well as newline characters removed.


how-to-remove-newline-character-from-a-list-in-python