Removing \r\n from a Python list after importing with readlines

前端 未结 4 1612
别跟我提以往
别跟我提以往 2020-12-31 01:50

I have saved a list of ticker symbols into a text file as follows:

MMM
ABT
ABBV
ANF
....

Then I use readlines to put the symbols into a Pyt

4条回答
  •  忘掉有多难
    2020-12-31 02:14

    You could replace \r\n with the empty string in a replace command.

    stocks = [x.replace("\r\n","") for x in stocks]
    

提交回复
热议问题