I have a list and every element of list consists of an escape sequence "\n" .. How to remove these "\n" from the elements?
Asked
Active
Viewed 152 times
-3
-
1Can you show us an example of the list ? – Shadesfear Sep 06 '19 at 11:34
-
3Possible duplicate of [Perform a string operation for every element in a Python list](https://stackoverflow.com/questions/7126916/perform-a-string-operation-for-every-element-in-a-python-list) – Sayse Sep 06 '19 at 11:38
1 Answers
4
Like this:
lst = ['\n', 'hello\n']
new_lst = [entry.replace('\n','') for entry in lst]
print(new_lst) #['', 'hello']

Carsten
- 2,765
- 1
- 13
- 28
-
its not working.. Is any library or built-in function available for this ?? – Salman Khatri Sep 07 '19 at 16:54
-
Well, you would need Python to run it. Apart from yet, nothing is needed. – Carsten Sep 09 '19 at 06:56