Sometimes, while working with String lists, we can have a problem in which we need to perform the deletion of extra characters that can be termed as unwanted and occur at end of each string. Let’s discuss a way in which this task can be performed.
Method : Using
map() + str.strip()
Combination of the above two functionalities can help us achieve this particular task. In this, we employ
strip(), which has the ability to remove the trailing and leading special unwanted characters from string list. The
map(), is used to extend the logic to each element in list.
The original list : ['\rgfg\t\n', 'is\n', '\t\tbest\r'] List after removal of special characters : ['gfg', 'is', 'best']
- Python | Convert list of strings and characters to list of characters
- Python | Remove empty strings from list of strings
- List comprehension and ord() in Python to remove all characters other than alphabets
- Python | Remove given character from Strings list
- Python | Remove Kth character from strings list
- Python | Remove prefix strings from list
- Python | Remove last character in list of strings
- Python | Remove all strings from a list of tuples
- Python | Remove all digits from a list of strings
- Python | Remove all characters except letters and numbers
- Python | Ways to remove n characters from start of given string
- Python | Remove all values from a list present in other list
- Python | Tokenizing strings in list of strings
- Python | Ways to split strings on Uppercase characters
- Python | Filter list of strings based on the substring list
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.