I have a list and every element of list consists of an escape sequence "\n" .. How to remove these "\n" from the elements?
-
1Can you show us an example of the list ?Shadesfear– Shadesfear2019-09-06 11:34:18 +00:00Commented Sep 6, 2019 at 11:34
-
3Possible duplicate of Perform a string operation for every element in a Python listSayse– Sayse2019-09-06 11:38:46 +00:00Commented Sep 6, 2019 at 11:38
Add a comment
|
1 Answer
Like this:
lst = ['\n', 'hello\n']
new_lst = [entry.replace('\n','') for entry in lst]
print(new_lst) #['', 'hello']
2 Comments
Salman Khatri
its not working.. Is any library or built-in function available for this ??
Carsten
Well, you would need Python to run it. Apart from yet, nothing is needed.