Python | Remove trailing/leading special characters from strings list
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']