Removing \r\n from a Python list after importing with readlines
That's basically how readlines
works. You could post-process it:
stocks = [x.rstrip() for x in stocks]
But I prefer not using readlines
at all if I don't want EOL character(s), instead doing:
stocks = open(textfile).read().splitlines()
Or even better:
with open(textfile) as f: stocks = f.read().splitlines()
(it almost certainly won't make a difference here, but using context managers to explicitly close file objects is a good habit to get into)