0

List: ['2\n','3\n',9\n]

I tried using delete and split, however I cannot delete / split '\n' specifically.

How do I remove \n from each entry?

Patrick Haugh
  • 55,247
  • 13
  • 83
  • 91

1 Answers1

0

You can use strip to remove \n

Let

l = ['2\n','3\n','9\n']
l = [ x.strip() for x in l ]

This will not convert your list into int to convert it into a int list you can do:

l = [ int(x) for x in l ]

vaku
  • 685
  • 8
  • 17