-3

I have a list and every element of list consists of an escape sequence "\n" .. How to remove these "\n" from the elements?

  • 1
    Can you show us an example of the list ? – Shadesfear Sep 06 '19 at 11:34
  • 3
    Possible 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 Answers1

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